Class: Elabs::Member::MemberContentApplicationController
- Inherits:
-
MemberApplicationController
- Object
- ActionController::Base
- ElabsApplicationController
- MemberApplicationController
- Elabs::Member::MemberContentApplicationController
- Defined in:
- app/controllers/elabs/member/member_content_application_controller.rb
Direct Known Subclasses
AlbumsController, ArticlesController, NotesController, ProjectsController, UploadsController
Constant Summary collapse
- ALLOWED_FIELDS =
[].freeze
- ALLOWED_RELATIONS =
{}.freeze
- DEFAULT_ORDER_FIELD =
'updated_at'.freeze
- MODEL =
nil
- PLURAL_NAME =
nil
- SINGULAR_NAME =
nil
Constants inherited from MemberApplicationController
Elabs::Member::MemberApplicationController::MAX_ITEMS_PER_PAGE
Instance Method Summary collapse
-
#create ⇒ Object
POST /articles POST /articles.json rubocop: disable Metrics/AbcSize.
-
#destroy ⇒ Object
DELETE /articles/1 DELETE /articles/1.json.
-
#edit ⇒ Object
GET /articles/1/edit.
-
#index ⇒ Object
GET /articles GET /articles.json rubocop: disable Metrics/AbcSize.
-
#new ⇒ Object
GET /articles/new.
-
#toggle_publication ⇒ Object
PUT /<entity>/1/toggle_publication.
-
#update ⇒ Object
PATCH/PUT /articles/1 PATCH/PUT /articles/1.json rubocop: disable Metrics/AbcSize.
Instance Method Details
#create ⇒ Object
POST /articles POST /articles.json rubocop: disable Metrics/AbcSize
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/elabs/member/member_content_application_controller.rb', line 38 def create build_entity respond_to do |format| if @entity.save entity_params format.html { redirect_to_index_with_notice :notice, format(_('%<model_name>s was successfully created.'), model_name: self.class::SINGULAR_NAME.capitalize) } format.json { render partial_name, status: :created, locals: { "#{self.class::SINGULAR_NAME}": @entity } } else format.html { render :new } format.json { render json: @entity.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /articles/1 DELETE /articles/1.json
74 75 76 77 78 79 80 81 |
# File 'app/controllers/elabs/member/member_content_application_controller.rb', line 74 def destroy @entity.changed_by = current_user @entity.destroy respond_to do |format| format.html { redirect_to index_url, notice: format(_('%<model_name>s was successfully destroyed.'), model_name: self.class::SINGULAR_NAME.capitalize) } format.json { head :no_content } end end |
#edit ⇒ Object
GET /articles/1/edit
33 |
# File 'app/controllers/elabs/member/member_content_application_controller.rb', line 33 def edit; end |
#index ⇒ Object
GET /articles GET /articles.json rubocop: disable Metrics/AbcSize
16 17 18 19 20 |
# File 'app/controllers/elabs/member/member_content_application_controller.rb', line 16 def index order = params['order_by'] || self.class::DEFAULT_ORDER_FIELD direction = params['direction'] || 'desc' create_instance_variable self.class::PLURAL_NAME, self.class::MODEL.by_member(current_user.id).order(order => direction).page(params[:page]).per(self.class::MAX_ITEMS_PER_PAGE) end |
#new ⇒ Object
GET /articles/new
25 26 27 28 29 30 |
# File 'app/controllers/elabs/member/member_content_application_controller.rb', line 25 def new entity = self.class::MODEL.new entity.language_id = current_user.preference.writing_language_id if current_user.preference.writing_language_id entity.license_id = current_user.preference.writing_license_id if current_user.preference.writing_license_id create_instance_variable self.class::SINGULAR_NAME, entity end |
#toggle_publication ⇒ Object
PUT /<entity>/1/toggle_publication
84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/elabs/member/member_content_application_controller.rb', line 84 def toggle_publication respond_to do |format| if @entity.toggle(:published).save format.html { redirect_to_index_with_notice :notice, (@entity) } format.json { render partial_name, status: :ok, locals: { "#{self.class::SINGULAR_NAME}": @entity } } else format.html { redirect_to_index_with_notice :error, 'An error prevented to update this entity' } format.json { render json: @entity.errors, status: :unprocessable_entity } end end end |
#update ⇒ Object
PATCH/PUT /articles/1 PATCH/PUT /articles/1.json rubocop: disable Metrics/AbcSize
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/elabs/member/member_content_application_controller.rb', line 57 def update @entity.changed_by = current_user respond_to do |format| if @entity.update entity_params format.html { redirect_to_index_with_notice :notice, format(_('%<model_name>s was successfully updated.'), model_name: self.class::SINGULAR_NAME.capitalize) } format.json { render partial_name, status: :ok, locals: { "#{self.class::SINGULAR_NAME}": @entity } } else format.html { render :edit } format.json { render json: @entity.errors, status: :unprocessable_entity } end end end |