Class: Maeku::EntriesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/maeku/entries_controller.rb', line 25

def create
  @entry = Entry.new(entry_params)
  @entry.author_id = current_author.id

  if @entry.save
    flash[:notice] = I18n.t 'controller.entries.create.success'
    redirect_to @entry
  else
    flash[:error] = I18n.t 'controller.entries.create.error'
    render :new
  end
end

#destroyObject



48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/maeku/entries_controller.rb', line 48

def destroy
  @entry = Entry.find(params[:id])
  if current_author?
    @entry.destroy
    flash[:notice] = I18n.t 'controller.entries.destroy.success'
    redirect_to entries_url
  else
    flash[:error] = I18n.t 'controller.entries.destroy.error'
    redirect_to entries_url
  end
end

#editObject



18
19
20
21
22
23
# File 'app/controllers/maeku/entries_controller.rb', line 18

def edit
  unless current_author?
    flash[:error] = I18n.t 'controller.entries.edit.error'
    redirect_to entries_url
  end
end

#indexObject



7
8
9
# File 'app/controllers/maeku/entries_controller.rb', line 7

def index
  @entries = current_author.entries
end

#newObject



14
15
16
# File 'app/controllers/maeku/entries_controller.rb', line 14

def new
  @entry = Entry.new
end

#showObject



11
12
# File 'app/controllers/maeku/entries_controller.rb', line 11

def show
end

#updateObject



38
39
40
41
42
43
44
45
46
# File 'app/controllers/maeku/entries_controller.rb', line 38

def update
  if @entry.update(entry_params) && current_author?
    flash[:notice] = I18n.t 'controller.entries.update.success'
    redirect_to @entry
  else
    flash[:error] = I18n.t 'controller.entries.update.error'
    render :edit
  end
end