5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-15 07:01:42 +00:00
panel/app/controllers/posts_controller.rb

56 lines
998 B
Ruby
Raw Normal View History

2018-01-29 22:19:10 +00:00
class PostsController < ApplicationController
before_action :authenticate!
def index
@site = find_site
end
2018-01-30 15:20:19 +00:00
def show
@site = find_site
@post = find_post(@site)
end
2018-01-31 20:29:27 +00:00
def new
@site = find_site
@post = Post.new(site: @site, front_matter: { date: Time.now })
end
def create
@site = find_site
@post = Post.new(site: @site, front_matter: post_params.to_hash)
if @post.save
redirect_to site_posts_path(@site)
else
render 'posts/new'
end
end
2018-01-31 20:29:27 +00:00
def edit
@site = find_site
@post = find_post(@site)
end
def update
p = post_params
2018-02-02 22:20:31 +00:00
@site = find_site
@post = find_post(@site)
2018-01-31 20:29:27 +00:00
2018-02-02 22:20:31 +00:00
@post.update_attributes(p)
2018-02-02 22:20:31 +00:00
if @post.save
redirect_to site_post_path(@site, @post)
else
render 'posts/edit'
end
2018-01-31 20:29:27 +00:00
end
private
2018-02-02 22:20:31 +00:00
# Solo permitir cambiar estos atributos de cada articulo
2018-01-31 20:29:27 +00:00
def post_params
2018-02-02 22:20:31 +00:00
params.require(:post).permit(:title, :date, :tags,
:categories, :content, :slug)
2018-01-31 20:29:27 +00:00
end
2018-01-29 22:19:10 +00:00
end