Class: Admin::LinksController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/stenographer/admin/links_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/stenographer/admin/links_controller.rb', line 13

def create
  @link = Link.new(link_params)

  if @link.save
    redirect_to admin_link_path(@link), notice: 'Link Created'
  else
    flash.now[:alert] = @link.errors.full_messages.to_sentence
    render :new
  end
end

#destroyObject



46
47
48
49
50
51
52
# File 'app/controllers/stenographer/admin/links_controller.rb', line 46

def destroy
  if @link.destroy
    redirect_to admin_links_path, notice: 'Link Destroyed'
  else
    redirect_to admin_link_path(@link), alert: @link.errors.full_messages.to_sentence
  end
end

#editObject



31
# File 'app/controllers/stenographer/admin/links_controller.rb', line 31

def edit; end

#indexObject



24
25
26
27
# File 'app/controllers/stenographer/admin/links_controller.rb', line 24

def index
  page = params[:page] || 1
  @links = Link.order(created_at: :desc).paginate(page: page, per_page: Stenographer.per_page)
end

#newObject



9
10
11
# File 'app/controllers/stenographer/admin/links_controller.rb', line 9

def new
  @link = Link.new
end

#showObject



29
# File 'app/controllers/stenographer/admin/links_controller.rb', line 29

def show; end

#updateObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/stenographer/admin/links_controller.rb', line 33

def update
  message = {}

  if @link.update(link_params)
    message[:notice] = 'Link Updated'

    redirect_to admin_link_path(@link), message
  else
    flash.now[:alert] = @link.errors.full_messages.to_sentence
    render :edit
  end
end