Class: Railspress::Admin::EntitiesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/railspress/admin/entities_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
# File 'app/controllers/railspress/admin/entities_controller.rb', line 20

def create
  @record = entity_class.new(entity_params)

  if @record.save
    redirect_to entity_index_path, notice: "#{entity_config.singular_label} created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



42
43
44
45
# File 'app/controllers/railspress/admin/entities_controller.rb', line 42

def destroy
  @record.destroy
  redirect_to entity_index_path, notice: "#{entity_config.singular_label} deleted."
end

#editObject



30
31
# File 'app/controllers/railspress/admin/entities_controller.rb', line 30

def edit
end

#image_editorObject

GET /admin/entities/:entity_type/:id/image_editor/:attachment Returns the expanded image editor in a Turbo Frame Pass ?compact=true to get the compact view (for Cancel)



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/railspress/admin/entities_controller.rb', line 50

def image_editor
  allowed = entity_config.fields
    .select { |_, f| [ :attachment, :attachments, :focal_point_image ].include?(f[:type]) }
    .keys.map(&:to_s)
  unless allowed.include?(params[:attachment])
    raise ActionController::RoutingError, "Invalid attachment"
  end
  @attachment_name = params[:attachment].to_sym

  if params[:compact] == "true"
    render partial: "railspress/admin/shared/image_section_compact",
           locals: {
             record: @record,
             attachment_name: @attachment_name,
             label: entity_config.singular_label
           }
  else
    # Ensure focal point is persisted before editing
    focal_point = @record.send("#{@attachment_name}_focal_point")
    focal_point.save! if focal_point.new_record?

    render partial: "railspress/admin/shared/image_section_editor",
           locals: {
             record: @record,
             attachment_name: @attachment_name,
             contexts: Railspress.image_contexts
           }
  end
end

#indexObject



9
10
11
# File 'app/controllers/railspress/admin/entities_controller.rb', line 9

def index
  @records = entity_class.order(created_at: :desc)
end

#newObject



16
17
18
# File 'app/controllers/railspress/admin/entities_controller.rb', line 16

def new
  @record = entity_class.new
end

#showObject



13
14
# File 'app/controllers/railspress/admin/entities_controller.rb', line 13

def show
end

#updateObject



33
34
35
36
37
38
39
40
# File 'app/controllers/railspress/admin/entities_controller.rb', line 33

def update
  purge_removed_attachments
  if @record.update(entity_params)
    redirect_to entity_index_path, notice: "#{entity_config.singular_label} updated."
  else
    render :edit, status: :unprocessable_entity
  end
end