Module: ScaffoldMarkup::Controllers::Base
- Defined in:
- lib/scaffold_markup/controllers/base.rb
Instance Attribute Summary collapse
-
#resource_class ⇒ Object
readonly
Returns the value of attribute resource_class.
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Attribute Details
#resource_class ⇒ Object (readonly)
Returns the value of attribute resource_class.
4 5 6 |
# File 'lib/scaffold_markup/controllers/base.rb', line 4 def resource_class @resource_class end |
Class Method Details
.included(base) ⇒ Object
6 7 8 |
# File 'lib/scaffold_markup/controllers/base.rb', line 6 def self.included(base) base.before_filter :identify_resource end |
Instance Method Details
#create ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/scaffold_markup/controllers/base.rb', line 26 def create @model = resource_class.new(params[resource_class.model_name.underscore]) if @model.save = "#{resource_class.model_name.human} successfully created" if params[:save_and_new] flash[:success] = redirect_to :action => :new else flash.now[:success] = render :show end else render :new end end |
#destroy ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/scaffold_markup/controllers/base.rb', line 52 def destroy @model = resource_class.find(params[:id]) if @model.destroy flash[:warning] = "#{resource_class.model_name.human} successfully removed" else flash[:danger] = "#{resource_class.model_name.human} could not be deleted" end redirect_to :action => :index end |
#edit ⇒ Object
22 23 24 |
# File 'lib/scaffold_markup/controllers/base.rb', line 22 def edit @model = resource_class.find(params[:id]) end |
#index ⇒ Object
10 11 12 |
# File 'lib/scaffold_markup/controllers/base.rb', line 10 def index @collection = resource_class.page(params[:page]) end |
#new ⇒ Object
18 19 20 |
# File 'lib/scaffold_markup/controllers/base.rb', line 18 def new @model = resource_class.new end |
#show ⇒ Object
14 15 16 |
# File 'lib/scaffold_markup/controllers/base.rb', line 14 def show @model = resource_class.find(params[:id]) end |
#update ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/scaffold_markup/controllers/base.rb', line 42 def update @model = resource_class.find(params[:id]) if @model.update_attributes(params[resource_class.model_name.underscore]) flash.now[:success] = "#{resource_class.model_name.human} successfully updated" render :show else render :edit end end |