Class: GenericResources::ResourcesController
- Inherits:
-
Object
- Object
- GenericResources::ResourcesController
- Defined in:
- app/controllers/generic_resources/resources_controller.rb
Instance Method Summary collapse
- #all ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#all ⇒ Object
5 6 7 |
# File 'app/controllers/generic_resources/resources_controller.rb', line 5 def all end |
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/generic_resources/resources_controller.rb', line 22 def create @resource = @resource_class.new(resource_attributes) if @resource.save flash[:notice] = I18n.t('generic_resources.controller.flash.notice.created', resource_name: @resource_class.model_name.human) else flash[:error] = I18n.t('generic_resources.controller.flash.error.not_created', resource_name: @resource_class.model_name.human, errors: @resource.errors.) end redirect_to_index end |
#destroy ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/generic_resources/resources_controller.rb', line 45 def destroy if GenericResource.resources[params[:resource_name]][:resource_deleteable] @resource.destroy flash[:notice] = I18n.t('generic_resources.controller.flash.notice.destroyed', resource_name: @resource_class.model_name.human) else flash[:notice] = I18n.t('generic_resources.controller.flash.error.not_destroyed', resource_name: @resource_class.model_name.human) end redirect_to_index end |
#edit ⇒ Object
18 19 20 |
# File 'app/controllers/generic_resources/resources_controller.rb', line 18 def edit render layout: nil if request.xhr? end |
#index ⇒ Object
9 10 11 |
# File 'app/controllers/generic_resources/resources_controller.rb', line 9 def index session["#{@resource_class.to_s.underscore}_page"] = params[:page].present? ? params[:page].to_i : 1 end |
#new ⇒ Object
13 14 15 16 |
# File 'app/controllers/generic_resources/resources_controller.rb', line 13 def new @resource = @resource_class.new render layout: nil if request.xhr? end |
#update ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/generic_resources/resources_controller.rb', line 34 def update if @resource.update_attributes(resource_attributes) flash[:notice] = I18n.t('generic_resources.controller.flash.notice.updated', resource_name: @resource_class.model_name.human) else flash[:error] = I18n.t('generic_resources.controller.flash.error.not_updated', resource_name: @resource_class.model_name.human, errors: @resource.errors.) end redirect_to_index end |