rails 4 and tons of stuff

This commit is contained in:
jomo
2014-04-14 06:26:37 +02:00
parent b740c4db3a
commit 7135d2690c
41 changed files with 349 additions and 206 deletions

View File

@@ -29,7 +29,7 @@ class BlogpostsController < ApplicationController
def create
if mod?
@post = Blogpost.new(params[:blogpost].slice(:title, :content))
@post = Blogpost.new(post_params)
@post.user_author = current_user
if @post.save
redirect_to @post, notice: 'Post has been created.'
@@ -47,7 +47,7 @@ class BlogpostsController < ApplicationController
@post = Blogpost.find(params[:id])
if mod? || @comment.author.is?(current_user)
@post.user_editor = current_user
if @post.update_attributes(params[:blogpost].slice(:title, :content, :user_editor))
if @post.update_attributes(post_params([:user_editor]))
redirect_to @post, notice: 'Post has been updated.'
else
flash[:alert] = "There was a problem while updating the post"
@@ -69,4 +69,13 @@ class BlogpostsController < ApplicationController
end
redirect_to blogposts_path
end
end
private
def post_params(add = [])
a = [:title, :content]
a += add
params.require(:blogpost).permit(a)
end
end