Class: EntriesController

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

Instance Method Summary collapse

Instance Method Details

#archiveObject

get /entries/archive/(:year)/(:month)



57
58
59
60
61
62
# File 'app/controllers/entries_controller.rb', line 57

def archive
  collect_months
  unless params[:month].nil?
    @collection = Entry.archive(params[:year], params[:month]).page_for_visitors current_user, current_page
  end
end

#createObject

post /entries



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

def create
  @entity = Entry.new creation_parameters
  if @entity.save
    redirect_to @entity
  else
    render :new, status: :bad_request
  end
end

#create_repostObject

post /entries/:id/reposts



70
71
72
73
74
75
76
77
# File 'app/controllers/entries_controller.rb', line 70

def create_repost
  @news = @entity.news.new(repost_parameters)
  if @news.save
    redirect_to @news
  else
    render :new_repost, status: :bad_request
  end
end

#destroyObject

delete /entries/:id



48
49
50
51
52
53
54
# File 'app/controllers/entries_controller.rb', line 48

def destroy
  if @entity.update(deleted: true)
    flash[:notice] = t('entries.destroy.success')
  end

  redirect_to entries_path
end

#editObject

get /entries/:id/edit



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

def edit
end

#indexObject

get /entries



9
10
11
# File 'app/controllers/entries_controller.rb', line 9

def index
  @collection = Entry.page_for_visitors(current_user, current_page)
end

#newObject

get /entries/new



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

def new
  @entity = Entry.new
end

#new_repostObject

get /entries/:id/reposts/new



65
66
67
# File 'app/controllers/entries_controller.rb', line 65

def new_repost
  @news = @entity.news.new
end

#showObject

get /entries/:id



29
30
31
32
# File 'app/controllers/entries_controller.rb', line 29

def show
  @entity.increment! :view_count
  set_adjacent_entities
end

#updateObject

patch /entries/:id



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

def update
  if @entity.update entity_parameters
    redirect_to @entity, notice: t('entries.update.success')
  else
    render :edit, status: :bad_request
  end
end