another big commit :D

This commit is contained in:
jomo
2013-10-07 04:59:21 +02:00
parent 2761387703
commit 5fac505a31
74 changed files with 1003 additions and 357 deletions

View File

@@ -10,7 +10,7 @@ class BlogpostsController < ApplicationController
end
def new
if current_user && current_user.rank >= rank_to_int("mod")
if mod?
@post = Blogpost.new
else
flash[:alert] = "You are not allowed to create a new post!"
@@ -20,19 +20,21 @@ class BlogpostsController < ApplicationController
def edit
@post = Blogpost.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @post.user.rank.to_i) || (current_user == @edit.user))
if mod?
else
flash[:alert] = "You are not allowed to update this post!"
flash[:alert] = "You are not allowed to edit this post!"
redirect_to @post
end
end
def create
if mod?
@post = Blogpost.new(params[:blogpost])
@post.user = current_user
@post.user_author = current_user
if @post.save
redirect_to @post, notice: 'Post has been created.'
else
flash[:alert] = @post.errors.first
render action: "new"
end
else
@@ -43,11 +45,12 @@ class BlogpostsController < ApplicationController
def update
@post = Blogpost.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @post.user.rank.to_i) || (current_user == @post.user))
if mod?
if @post.update_attributes(params[:blogpost])
redirect_to @post, notice: 'Post has been updated.'
else
flash[:alert] = "There was a problem while updating the post"
raise @post.errors
render action: "edit"
end
end
@@ -55,7 +58,7 @@ class BlogpostsController < ApplicationController
def destroy
@post = Blogpost.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @post.user.rank.to_i) || (current_user == @post.user))
if mod?
if @post.destroy
flash[:notice] = "Post deleted!"
else