diff options
author | jomo <github@jomo.tv> | 2013-06-24 13:29:39 +0200 |
---|---|---|
committer | jomo <github@jomo.tv> | 2013-06-24 13:29:39 +0200 |
commit | fb52e8bed20142d0d08b2f0568a14172ab62844c (patch) | |
tree | a4e50ca07194906652abf1b71cea6ca0e3e0dbf9 /app/controllers/blogposts_controller.rb | |
parent | 7a894f4f6aecf3d6dcf103cf8cd51c52ab6f2655 (diff) |
many things, comments working.
Diffstat (limited to 'app/controllers/blogposts_controller.rb')
-rw-r--r-- | app/controllers/blogposts_controller.rb | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb index 9df5451..1992538 100644 --- a/app/controllers/blogposts_controller.rb +++ b/app/controllers/blogposts_controller.rb @@ -1,19 +1,14 @@ class BlogpostsController < ApplicationController - # GET /blogposts - # GET /blogposts.json + def index @posts = Blogpost.all.reverse end - # GET /blogposts/1 - # GET /blogposts/1.json def show @post = Blogpost.find(params[:id]) - @comment = Comment.new(:blogpost_id => @post.id) + @comment = Comment.new(:blogpost => @post) end - # GET /blogposts/new - # GET /blogposts/new.json def new @post = Blogpost.new end @@ -26,12 +21,17 @@ class BlogpostsController < ApplicationController # POST /blogposts # POST /blogposts.json def create - @post = Blogpost.new(params[:blogpost]) - @post.user_id = current_user.id unless current_user.nil? - if @post.save - redirect_to @post, notice: 'Post has been created.' + if current_user && current_user.rank >= rank_to_int("mod") + @post = Blogpost.new(params[:blogpost]) + @post.user_id = current_user.id unless current_user.nil? + if @post.save + redirect_to @post, notice: 'Post has been created.' + else + render action: "new" + end else - render action: "new" + flash[:alert] = "You are not allowed to create new posts" + redirect_to blog_path end end @@ -53,6 +53,6 @@ class BlogpostsController < ApplicationController @post = Blogpost.find(params[:id]) @post.destroy - redirect_to blogposts_url + redirect_to blog_url end end |