Module ResourceController::Helpers::SingletonCustomizations
In: ../lib/resource_controller/helpers/singleton_customizations.rb

Methods

Public Class methods

[Source]

    # File ../lib/resource_controller/helpers/singleton_customizations.rb, line 8
 8:       def self.included(subclass)
 9:         subclass.class_eval do  
10:           methods_to_undefine = [:param, :index, :collection, :load_collection, :collection_url, 
11:             :collection_path, :hash_for_collection_url, :hash_for_collection_path]
12:           methods_to_undefine.each { |method| undef_method(method) if method_defined? method }
13:       
14:           class << self
15:             def singleton?
16:               true
17:             end
18:           end
19:         end
20:       end

[Source]

    # File ../lib/resource_controller/helpers/singleton_customizations.rb, line 15
15:             def singleton?
16:               true
17:             end

Protected Instance methods

Builds the object, but doesn‘t save it, during the new, and create action.

[Source]

    # File ../lib/resource_controller/helpers/singleton_customizations.rb, line 53
53:         def build_object
54:           @object ||= singleton_build_object_base.send parent? ? "build_#{model_name}".to_sym : :new, object_params
55:         end

Used to fetch the current object in a singleton controller.

By defult this method is able to fetch the current object for resources nested with the :has_one association only. (i.e. /users/1/image # => @user.image) In other cases you should override this method and provide your custom code to fetch a singleton resource object, like using a session hash.

class AccountsController < ResourceController::Singleton

  private
    def object
      @object ||= Account.find(session[:account_id])
    end
  end

[Source]

    # File ../lib/resource_controller/helpers/singleton_customizations.rb, line 35
35:         def object
36:           @object ||= parent? ? end_of_association_chain : nil
37:         end

Used internally to provide the options to smart_url in a singleton controller.

[Source]

    # File ../lib/resource_controller/helpers/singleton_customizations.rb, line 47
47:         def object_url_options(action_prefix = nil, alternate_object = nil)
48:           [action_prefix] + namespaces + [parent_url_options, route_name.to_sym]
49:         end

Returns the :has_one association proxy of the parent. (i.e. /users/1/image # => @user.image)

[Source]

    # File ../lib/resource_controller/helpers/singleton_customizations.rb, line 41
41:         def parent_association
42:           @parent_association ||= parent_object.send(model_name.to_sym)
43:         end

Singleton controllers don‘t build off of association proxy, so we can‘t use end_of_association_chain here

[Source]

    # File ../lib/resource_controller/helpers/singleton_customizations.rb, line 59
59:         def singleton_build_object_base
60:           parent? ? parent_object : model
61:         end

[Validate]