Sha256: 6ae84a50a676a7b90eb6a401418e8bf5ad94aadb72411bcfe4f8f3ffb137725f

Contents?: true

Size: 1.44 KB

Versions: 33

Compression:

Stored size: 1.44 KB

Contents

class Admin::ScaffoldController < Admin::BaseController
  respond_to :html, :js
  before_filter :prepend_resource_views_prefix
    
  def index
    @search = current_resource_class.search(params[:search])
    set_collection @search.page(params[:page] || 1)
  end

  def new
     set_object current_resource_class.new  
  end
  
  def edit
  end
  
  def create
      set_object current_resource_class.new(params[:"#{resource_name}"])
      
      if current_resource.respond_to?(:author)
        current_resource.author ||= current_user
      end
      
      current_resource.save
      respond_with(current_resource)
  end
  
  def update
    current_resource.attributes = params[:"#{resource_name}"]
    current_resource.save
    respond_with(current_resource)
  end
  
  def destroy
    current_resource.destroy
    respond_with(current_resource)
  end
  
  protected
  
  # overrides checkin default
  def fetch_object
    if params[:id]
      set_object(current_resource_class.find(params[:id]))
    end
  end
    
  # helpers overrides
  def current_resource_class
    @current_resource_class ||= params[:_admin_resource_type].classify.constantize
  end

  private 

  def prepend_resource_views_prefix
    lookup_context.prefixes.unshift "admin/#{collection_name}"
  end

  def set_object(value)
    instance_variable_set("@#{resource_name}", value)    
  end
  
  def set_collection(value)
    instance_variable_set("@#{collection_name}", value)
  end
  
  
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
fullstack-admin-0.2.3 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.2.2 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.2.1 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.56 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.55 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.54 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.53 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.52 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.51 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.50 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.49 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.48 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.47 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.46 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.45 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.44 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.43 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.42 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.41 app/controllers/admin/scaffold_controller.rb
fullstack-admin-0.1.40 app/controllers/admin/scaffold_controller.rb