| Class | CommentsController |
| In: |
app/controllers/comments_controller.rb
|
| Parent: | ApplicationController |
POST /comments POST /comments.xml
# File app/controllers/comments_controller.rb, line 33
33: def create
34: @comment = @parent.comments.new(params[:comment])
35: @comment.request = request
36: if logged_in?
37: @comment.user_id = current_user.id
38: end
39:
40: respond_to do |format|
41: if @parent.has_comments? && !@parent.comments_closed? && @comment.save
42: format.html {
43: if @comment.spam?
44: msg = t('comments.sorry_marked_as_spam')
45: elsif @comment.approved?
46: msg = t('comments.comentario_guardado')
47: else
48: msg = t('comments.comment_pending')
49: end
50: flash[:notice] = msg
51: redirect_to(@parent)
52: }
53: format.js {
54: if @comment.approved?
55: render :update do |page|
56: page.insert_html :bottom, "doc_comments", :partial => "comment", :object => @comment
57: page.visual_effect :highlight, "comment_#{@comment.id}"
58: page.replace_html :comment_row, :partial => "new_comment_link"
59: page.insert_html :before, "comment_#{@comment.id}", "<div class='flash_notice'>#{t('comments.comentario_guardado')}</div>"
60: end
61: else
62: if @comment.spam?
63: msg = t('comments.sorry_marked_as_spam')
64: else
65: msg = t('comments.comment_pending')
66: end
67: render :update do |page|
68: page.replace_html :comment_row, :partial => "new_comment_link"
69: page.insert_html :bottom, "doc_comments",
70: "<div class='flash_notice'>#{msg}</div>"
71: end
72: end
73: }
74: else
75: format.html { render :action => "new" }
76: format.js {
77: render :update do |page|
78: page.replace_html :comment_error, "<div class='flash_error'>
79: #{t('comments.no_publicado')}<br/>
80: </div>
81: #{error_messages_for(:comment)}"
82: end
83: }
84: end
85: end
86: end
DELETE /comments/1 DELETE /comments/1.xml
# File app/controllers/comments_controller.rb, line 90
90: def destroy
91: @comment = @parent.comments.find(params[:id])
92: @comment.destroy
93:
94: respond_to do |format|
95: format.html { redirect_to(comments_url) }
96: format.xml { head :ok }
97: end
98: end
# File app/controllers/comments_controller.rb, line 6
6: def index
7: @comments = Comment.approved.find(:all, :order => "created_at DESC", :limit => 20)
8: respond_to do |format|
9: #format.html
10: format.rss { render :layout=>false}
11: end
12: end
GET /comments/new GET /comments/new.xml
# File app/controllers/comments_controller.rb, line 16
16: def new
17: @comment = @parent.comments.new
18:
19: unless @parent.comments_closed?
20: respond_to do |format|
21: format.html # new.html.erb
22: format.js {
23: render :update do |page|
24: page.replace_html :comment_row, :partial => 'new'
25: end
26: }
27: end
28: end
29: end
# File app/controllers/comments_controller.rb, line 100
100: def photo
101: @comment = Comment.find(params[:id])
102: render :action => 'photo', :layout => false
103: end
Marca un comentario como inadecuado. Actualmente esta funcionalidad está desactivada.
Para activarla de nuevo hay que descomentar un partial en app/views/comments/_vote.html.erb
e incluir la ruta "report_abuse" en config/routes.rb
# File app/controllers/comments_controller.rb, line 138
138: def report_abuse
139: @comment = Comment.find(params[:id])
140:
141: @comment.abuse_counter += 1
142: if @comment.save
143: respond_to do |format|
144: format.html {
145: flash[:notice] = t('comments.abuse_thank_you2')
146: redirect_to @comment.parent
147: }
148: format.js {
149: render :update do |page|
150: page.replace_html "abuse_#{@comment.id}", "<span>#{t('comments.abuse_thank_you')}</span>"
151: end
152: }
153: end
154: else
155: respond_to do |format|
156: format.html {
157: flash[:error] = t('comments.abuse_unsaved')
158: redirect_to @comment.parent
159: }
160: format.js {
161: logger.info "El aviso no se ha guardado: #{@comment.errors.inspect}"
162: render :nothing => true
163: }
164: end
165: end
166: end
# File app/controllers/comments_controller.rb, line 105
105: def vote
106: @comment = Comment.find(params[:id])
107:
108: @comment.ratings.build(:rating => params[:vote].to_i)
109: if @comment.save
110: respond_to do |format|
111: format.html {
112: flash[:notice] = t('comments.vote_thank_you')
113: redirect_to @comment.commentable
114: }
115: format.js {
116: render :update do |page|
117: page.replace "comment_rating_#{@comment.id}", :partial => "/comments/voted", :locals => {:comment => @comment, :vote => params[:vote].to_i}
118: end
119: }
120: end
121: else
122: respond_to do |format|
123: format.html {
124: flash[:error] = t('comments.vote_unsaved')
125: redirect_to @comment.parent
126: }
127: format.js {
128: logger.info "El voto no se ha guardado: #{@comment.errors.inspect}"
129: render :nothing => true
130: }
131: end
132: end
133: end