Class: Elabs::Member::MemberContentApplicationController

Inherits:
MemberApplicationController show all
Defined in:
app/controllers/elabs/member/member_content_application_controller.rb

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

Instance Method Details

#createObject

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

#destroyObject

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

#editObject

GET /articles/1/edit



33
# File 'app/controllers/elabs/member/member_content_application_controller.rb', line 33

def edit; end

#indexObject

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

#newObject

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_publicationObject

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, publication_message(@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

#updateObject

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