work on forum post controller
This commit is contained in:
@@ -1,37 +1,52 @@
|
||||
class ForumPostsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only, :except => [:index, :show]
|
||||
rescue_from User::PrivilegeError, :with => "static/access_denied"
|
||||
|
||||
def new
|
||||
@forum_post = ForumPost.new(:topic_id => params[:topic_id])
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
def edit
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
check_privilege(@forum_post)
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
def index
|
||||
@forum_posts = ForumPost.search(params[:search])
|
||||
respond_with(@forum_posts)
|
||||
end
|
||||
|
||||
def show
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
def create
|
||||
@forum_post = ForumPost.new(params[:forum_post])
|
||||
if @forum_post.save
|
||||
redirect_to forum_post_path(@forum_post)
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
def update
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
if @forum_post.update_attributes(params[:forum_post])
|
||||
redirect_to forum_post_path(@forum_post)
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
check_privilege(@forum_post)
|
||||
@forum_post.update_attributes(params[:forum_post])
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
check_privilege(@forum_post)
|
||||
@forum_post.destroy
|
||||
redirect_to forum_topic_path(@forum_post.topic_id)
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
private
|
||||
def check_privilege(forum_post)
|
||||
if !forum_post.editable_by?(CurrentUser.user)
|
||||
raise User::PrivilegeError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,11 +43,11 @@ class ForumTopicsController < ApplicationController
|
||||
@forum_topic.destroy
|
||||
respond_with(@forum_topic)
|
||||
end
|
||||
|
||||
private
|
||||
def check_privilege(forum_topic)
|
||||
if !forum_topic.editable_by?(CurrentUser.user)
|
||||
raise User::PrivilegeError
|
||||
end
|
||||
|
||||
private
|
||||
def check_privilege(forum_topic)
|
||||
if !forum_topic.editable_by?(CurrentUser.user)
|
||||
raise User::PrivilegeError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ class UploadsController < ApplicationController
|
||||
if params[:url]
|
||||
@post = Post.find_by_source(params[:url])
|
||||
end
|
||||
respond_with(@upload)
|
||||
end
|
||||
|
||||
def index
|
||||
@@ -16,6 +17,7 @@ class UploadsController < ApplicationController
|
||||
|
||||
def show
|
||||
@upload = Upload.find(params[:id])
|
||||
respond_with(@upload)
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -26,8 +28,6 @@ class UploadsController < ApplicationController
|
||||
def update
|
||||
@upload = Upload.find(params[:id])
|
||||
@upload.process!
|
||||
render :update do |page|
|
||||
page.reload
|
||||
end
|
||||
respond_with(@upload)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user