Class: Tramway::EntitiesController
- Inherits:
-
Object
- Object
- Tramway::EntitiesController
- Defined in:
- app/controllers/tramway/entities_controller.rb
Overview
Main controller for entities pages
Instance Method Summary collapse
-
#create ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#destroy ⇒ Object
rubocop:enable Metrics/AbcSize.
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
rubocop:disable Metrics/AbcSize
43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/tramway/entities_controller.rb', line 43 def create @record = tramway_form model_class.new, namespace: entity.namespace if @record.submit params[model_class.model_name.param_key] redirect_to public_send(entity.show_helper_method, @record.id), notice: t('tramway.notices.created') else render :new end end |
#destroy ⇒ Object
rubocop:enable Metrics/AbcSize
64 65 66 67 68 69 70 |
# File 'app/controllers/tramway/entities_controller.rb', line 64 def destroy @record = model_class.find(params[:id]) @record.destroy redirect_to public_send(entity.index_helper_method), notice: t('tramway.notices.deleted') end |
#edit ⇒ Object
38 39 40 |
# File 'app/controllers/tramway/entities_controller.rb', line 38 def edit @record = tramway_form model_class.find(params[:id]), namespace: entity.namespace end |
#index ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/tramway/entities_controller.rb', line 13 def index if index_scope.present? model_class.public_send(index_scope) else model_class.order(id: :desc) end.page(params[:page]) => entities @entities = entities @namespace = entity.namespace end |
#new ⇒ Object
34 35 36 |
# File 'app/controllers/tramway/entities_controller.rb', line 34 def new @record = tramway_form model_class.new, namespace: entity.namespace end |
#show ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'app/controllers/tramway/entities_controller.rb', line 25 def show @record = tramway_decorate( model_class.find(params[:id]), namespace: entity.namespace ).with(view_context:) set_associations end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/tramway/entities_controller.rb', line 53 def update @record = tramway_form model_class.find(params[:id]), namespace: entity.namespace if @record.submit params[model_class.model_name.param_key] redirect_to public_send(entity.show_helper_method, @record.id), notice: t('tramway.notices.updated') else render :edit end end |