-
Notifications
You must be signed in to change notification settings - Fork 0
/
pages_controller.rb
58 lines (46 loc) · 1.14 KB
/
pages_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true
class PagesController < ApplicationController
def index
@pages = Page.all
end
def show
@page = Page.find(params[:id])
end
def new
@page = Page.new
end
def edit
@page = Page.find(params[:id])
end
def create
@page = Page.new(page_params)
if @page.save
message = @page.user_message || 'Page was successfully created.'
redirect_to page_path(@page), notice: message
else
render :new, status: :unprocessable_entity
end
end
def update
@page = Page.find(params[:id])
if @page.update(page_params)
message = @page.user_message || 'Page was successfully updated.'
redirect_to page_path(@page), notice: message
else
render :edit, status: :unprocessable_entity
end
end
def destroy
@page = Page.find(params[:id])
if @page.destroy
message = @page.user_message || 'Page was successfully destroyed.'
redirect_to pages_root_path, notice: message
else
render :show, status: :unprocessable_entity
end
end
private
def page_params
params.require(:page).permit(:title, :content, :domain)
end
end