Class: Commentable::Controller
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Commentable::Controller
- Defined in:
- lib/commentable/controller.rb
Instance Method Summary collapse
- #build_comment(params = nil) ⇒ Object
- #comment_url ⇒ Object
- #commentable_url ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #load_commentable ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #spam ⇒ Object
- #troll ⇒ Object
- #update ⇒ Object
Instance Method Details
#build_comment(params = nil) ⇒ Object
71 72 73 74 75 |
# File 'lib/commentable/controller.rb', line 71 def build_comment(params = nil) comment = @commentable.comments.build(params) comment.user_ip = request.remote_ip if comment.respond_to?(:user_ip) comment end |
#comment_url ⇒ Object
63 64 65 |
# File 'lib/commentable/controller.rb', line 63 def comment_url polymorphic_url(@commentable, :anchor => "C#{@comment.to_param}") end |
#commentable_url ⇒ Object
67 68 69 |
# File 'lib/commentable/controller.rb', line 67 def commentable_url @commentable end |
#create ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/commentable/controller.rb', line 24 def create @comment = build_comment(params[:comment]) @comment.save respond_with(@commentable, @comment) do |format| format.html do if @comment.persisted? redirect_to comment_url else render 'new' end end end end |
#destroy ⇒ Object
57 58 59 60 61 |
# File 'lib/commentable/controller.rb', line 57 def destroy @comment = @commentable.comments.find(params[:id]) @comment.destroy respond_with(@commentable, @comment, :location => commentable_url) end |
#edit ⇒ Object
20 21 22 |
# File 'lib/commentable/controller.rb', line 20 def edit @comment = @commentable.comments.find(params[:id]) end |
#index ⇒ Object
5 6 7 8 |
# File 'lib/commentable/controller.rb', line 5 def index @comments = @commentable.comments.all respond_with(@commentable, @comments) end |
#load_commentable ⇒ Object
77 78 79 80 |
# File 'lib/commentable/controller.rb', line 77 def load_commentable id = params["#{params[:commentable]}_id"] @commentable = params[:commentable].camelize.constantize.find(id) end |
#new ⇒ Object
15 16 17 18 |
# File 'lib/commentable/controller.rb', line 15 def new @comment = build_comment respond_with(@commentable, @comment) end |
#show ⇒ Object
10 11 12 13 |
# File 'lib/commentable/controller.rb', line 10 def show @comment = @commentable.comments.find(params[:id]) respond_with(@commentable, @comment) end |
#spam ⇒ Object
45 46 47 48 49 |
# File 'lib/commentable/controller.rb', line 45 def spam @comment = @commentable.comments.find(params[:id]) @comment.toggle!(:spam) respond_with(@commentable, @comment, :location => comment_url) end |
#troll ⇒ Object
51 52 53 54 55 |
# File 'lib/commentable/controller.rb', line 51 def troll @comment = @commentable.comments.find(params[:id]) @comment.toggle!(:troll) respond_with(@commentable, @comment, :location => comment_url) end |
#update ⇒ Object
39 40 41 42 43 |
# File 'lib/commentable/controller.rb', line 39 def update @comment = @commentable.comments.find(params[:id]) @comment.update_attributes(params[:comment]) respond_with(@commentable, @comment, :location => comment_url) end |