Sha256: 6f97b0cd81ca54e382d927db21a0e0662d510d24e33a7b8967b1a55c23c174ee

Contents?: true

Size: 1.34 KB

Versions: 19

Compression:

Stored size: 1.34 KB

Contents

module LoadBehind
  class ControllerResource < CanCan::ControllerResource
    def initialize(controller, name, parent = nil, options = {})
      super(controller, name, parent, options)
    end

    def load_resource
      puts "AjaxLoading::load_resource"
      params = @controller.params
      set_controller_var 'container', params[:container] if params.has_key?(:container)

      if params.has_key?(:associated)
        ass_params = params[:associated]
        relation = ass_params["class_name"].constantize.find(ass_params["id"])
        association = ass_params["association"]

        set_controller_var 'container', get_controller_var('container') ||
            relation.element_id(:show, association)

        self.model_instance = relation.send(association)
      elsif collection_action?
        self.model_instance = model_class.where('1=1')
      else
        super
      end
      set_controller_var 'container', get_controller_var('container') || 'main_container'
    end

    def find(id)
      self.model_instance ||= base.lookup(id)
    end

    private

    def set_controller_var(name, value)
      name = '@'+name unless name.include?('@')
      @controller.instance_variable_set(name, value)
    end
    def get_controller_var(name)
      name = '@'+name unless name.include?('@')
      @controller.instance_variable_get(name)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
casey_jones-0.1.2 lib/ajax_loading/controller_resource.rb
casey_jones-0.1.1 lib/ajax_loading/controller_resource.rb
casey_jones-0.1.0 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.121 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.120 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.119 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.118 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.117 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.116 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.115 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.114 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.113 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.112 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.111 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.110 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.109 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.108 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.107 lib/ajax_loading/controller_resource.rb
casey_jones-0.0.106 lib/ajax_loading/controller_resource.rb