Class: Iron::EntriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/iron/entries_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/iron/entries_controller.rb', line 38

def create
  @entry = @content_type.entries.build(entry_params)

  if @entry.save
    if @entry.content_type.single?
      redirect_to entry_content_type_url(@entry.content_type), notice: t("iron.entries.notifications.created", content_type: @entry.content_type.name)
    else
      redirect_to edit_entry_url(@entry), notice: t("iron.entries.notifications.created", content_type: @entry.content_type.name)
    end
  else
    if @entry.errors.any?
      flash.now[:alert] = t("iron.entries.alerts.validation_errors")
    else
      flash.now[:alert] = t("iron.entries.alerts.create_failed", content_type: @entry.content_type.name)
    end
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



74
75
76
77
# File 'app/controllers/iron/entries_controller.rb', line 74

def destroy
  @entry.destroy!
  redirect_to content_type_entries_path(@entry.content_type), notice: t("iron.entries.notifications.destroyed"), status: :see_other
end

#editObject



35
36
# File 'app/controllers/iron/entries_controller.rb', line 35

def edit
end

#entryObject



16
17
18
# File 'app/controllers/iron/entries_controller.rb', line 16

def entry
  @entry = @content_type.entry
end

#indexObject



8
9
10
11
12
13
14
# File 'app/controllers/iron/entries_controller.rb', line 8

def index
  if @content_type.single?
    redirect_to entry_content_type_path(@content_type)
  else
    @pagy, @entries = pagy(:offset, @content_type.entries.order(updated_at: :desc), limit: 25)
  end
end

#newObject



31
32
33
# File 'app/controllers/iron/entries_controller.rb', line 31

def new
  @entry = @content_type.entries.build
end

#searchObject



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/iron/entries_controller.rb', line 20

def search
  @definition = FieldDefinitions::ReferenceList.find(params[:reference_list_field_definition_id])
  @entries = Entry.with_content_type(@definition.supported_content_types.pluck(:id))
  @entries = @entries.search_by_title(params[:q]) if params[:q].present?

  @reference_list_field_definition_id = params[:reference_list_field_definition_id]
  @form_field_name = params[:form_field_name]
  @reference_list_dom_id = params[:reference_list_dom_id]
  render layout: false
end

#updateObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/iron/entries_controller.rb', line 57

def update
  if @entry.update(entry_params)
    if @entry.content_type.single?
      redirect_to entry_content_type_url(@entry.content_type, locale: @locale.code), notice: t("iron.entries.notifications.updated", content_type: @entry.content_type.name)
    else
      redirect_to edit_entry_url(@entry, locale: @locale.code), notice: t("iron.entries.notifications.updated", content_type: @entry.content_type.name)
    end
  else
    if @entry.errors.any?
      flash.now[:alert] = t("iron.entries.alerts.validation_errors")
    else
      flash.now[:alert] = t("iron.entries.alerts.update_failed", content_type: @entry.content_type.name)
    end
    render :edit, status: :unprocessable_entity
  end
end