Class: Bhf::EntriesController

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

Direct Known Subclasses

EmbedEntriesController

Instance Method Summary collapse

Instance Method Details

#createObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/bhf/entries_controller.rb', line 29

def create
  before_save
  if @object.save
    manage_relations
    after_save

    if @quick_edit
      render json: object_to_bhf_hash, status: :ok
    else
      redirect_after_save(notice: set_message('create.success', @model), referral_entry: {id: @object.id, platform: @platform.name})
    end
  else
    @form_url = entries_path(@platform.name)

    r_settings = {status: :unprocessable_entity}
    if @quick_edit
      r_settings[:layout] = 'bhf/quick_edit'
      r_settings[:formats] = [:html]
    end
    render :new, r_settings
  end
end

#destroyObject



99
100
101
102
103
104
105
106
107
108
# File 'app/controllers/bhf/entries_controller.rb', line 99

def destroy
  object = @object.destroy
  if @quick_edit
    respond_to do |f|
      f.json { render status: :ok, json: object }
    end
  else
    redirect_back_or_default(page_url(@platform.page_name, anchor: "#{@platform.name}_platform"), notice: set_message('destory.success', @model))
  end
end

#duplicateObject



78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/bhf/entries_controller.rb', line 78

def duplicate
  new_record = @object.dup
  new_record.before_bhf_duplicate(@object) if new_record.respond_to?(:before_bhf_duplicate)
  if new_record.save
    new_record.after_bhf_duplicate(@object) if new_record.respond_to?(:after_bhf_duplicate)
    redirect_to(page_url(@platform.page_name, anchor: "#{@platform.name}_platform"), notice: set_message('duplicate.success', @model), flash: {referral_entry: {id: new_record.id, platform: @platform.name}})
  else
    redirect_to(page_url(@platform.page_name, anchor: "#{@platform.name}_platform"), notice: set_message('duplicate.error', @model))
  end
end

#editObject



12
13
14
15
16
17
18
# File 'app/controllers/bhf/entries_controller.rb', line 12

def edit
  render file: 'public/404.html', layout: false and return unless @object

  @form_url = entry_path(@platform.name, @object)

  render layout: 'bhf/quick_edit' if @quick_edit
end

#newObject



6
7
8
9
10
# File 'app/controllers/bhf/entries_controller.rb', line 6

def new
  @form_url = entries_path(@platform.name)

  render layout: 'bhf/quick_edit' if @quick_edit
end

#showObject



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

def show
  render file: 'public/404.html', layout: false and return unless @object

  respond_to do |format|
    format.html
    format.json  { render json: @object }
  end
end

#sortObject



89
90
91
92
93
94
95
96
97
# File 'app/controllers/bhf/entries_controller.rb', line 89

def sort
  params[:order].each do |order|
    @model.
      find(order[1].gsub("_#{@platform.name}", '')).
      update_attribute(@platform.sortable_property, order[0].to_i)
  end

  head :ok
end

#updateObject



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
# File 'app/controllers/bhf/entries_controller.rb', line 52

def update
  render file: 'public/404.html', layout: false and return unless @object

  before_save
  if @object.update_attributes(@permited_params)
    puts 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    manage_relations
    after_save

    if @quick_edit
      render json: object_to_bhf_hash, status: :ok
    else
      redirect_after_save(notice: set_message('update.success', @model), referral_entry: {id: @object.id, platform: @platform.name})
    end
  else
    @form_url = entry_path(@platform.name, @object)

    r_settings = {status: :unprocessable_entity}
    if @quick_edit
      r_settings[:layout] = 'bhf/quick_edit'
      r_settings[:formats] = [:html]
    end
    render :edit, r_settings
  end
end