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
47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/tramway/entities_controller.rb', line 47 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
68 69 70 71 72 73 74 |
# File 'app/controllers/tramway/entities_controller.rb', line 68 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
42 43 44 |
# File 'app/controllers/tramway/entities_controller.rb', line 42 def edit @record = tramway_form model_class.find(params[:id]), namespace: entity.namespace end |
#index ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/tramway/entities_controller.rb', line 15 def index if index_scope.present? model_class.public_send(index_scope) else model_class.order(id: :desc) end => entities entities = search(entities) entities = entities.page(params[:page]) @entities = entities @namespace = entity.namespace end |
#new ⇒ Object
38 39 40 |
# File 'app/controllers/tramway/entities_controller.rb', line 38 def new @record = tramway_form model_class.new, namespace: entity.namespace end |
#show ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'app/controllers/tramway/entities_controller.rb', line 29 def show @record = tramway_decorate( model_class.find(params[:id]), namespace: entity.namespace ).with(view_context:) set_associations end |
#update ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/tramway/entities_controller.rb', line 57 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 |