Crear un comentario
# File app/controllers/comments_controller.rb, line 59 def create if params[:data].present? json_params = JSON.parse(params[:data]) comment_params = {:body => json_params["comment_text"]} else comment_params = params[:comment] end comment_params.merge!({:user_id => current_user.id}) if logged_in? @comment = @parent.comments.new(comment_params) @comment.request = request @tracking_url = "/#{I18n.locale}/commented" respond_to do |format| if @parent.has_comments? && !@parent.comments_closed? && @comment.save format.html { @msg = if @comment.spam? t('comments.sorry_marked_as_spam') elsif @comment.approved? t('comments.comentario_guardado') else t('comments.comment_pending') end if request.xhr? render :partial => "comment_created", :layout => false else flash[:notice] = @msg flash[:tracking] = @tracking_url redirect_to(@parent) end } format.floki { render :action => 'create.json', :content_type => 'application/json', :layout => false } else if !@parent.has_comments? || @parent.comments_closed? @comment.errors.add(:base, I18n.t('comments.comentarios_cerrados')) end format.html { if request.xhr? render :json => "<li class='info'><div class='alert alert-error'>#{([I18n.t('comments.no_enviado')]+@comment.errors.full_messages)}</div></li>".to_json, :status => :error else render :action => "new" end return } format.floki end end end
# File app/controllers/comments_controller.rb, line 44 def department @department = Department.find(params[:id]) @feed_title = t('comments.feed_title', :name => @department.name) organization_ids = [@department.id] + @department.organization_ids # Se supone que si una noticia tiene comentarios es porque esta ya publicada y se muestra en irekia. # No sabemos si esta traducida, pero creo que es mejor mostrarlo de todas formas. # Por lo tanto, no ponemos condiciones en ninguno de estos campos. @comments = Comment.approved.find(:all, :joins => "INNER JOIN documents ON (comments.commentable_id=documents.id AND commentable_type='Document')", :conditions => "organization_id in (#{organization_ids.join(',')})", :order => "created_at DESC", :limit => 20) render :action => "index.rss", :layout => false end
Eliminar un comentario
# File app/controllers/comments_controller.rb, line 109 def destroy @comment = @parent.comments.find(params[:id]) @comment.destroy respond_to do |format| format.html { redirect_to(comments_url) } format.xml { head :ok } end end
Listado de todos los comentarios
# File app/controllers/comments_controller.rb, line 28 def index if params[:news_id] news = News.find(params[:news_id]) @comments = news.comments.approved.find(:all, :order => "created_at DESC", :limit => 20) @feed_title = t('comments.feed_title', :name => news.title) else @comments = Comment.approved.find(:all, :order => "created_at DESC", :limit => 20) @feed_title = t('comments.feed_title', :name => Notifier::SERVICENAME) end respond_to :rss # respond_to do |format| # #format.html # format.rss { render :layout=>false} # end end
# File app/controllers/comments_controller.rb, line 150 def list @comments = @parent.comments.approved.find(:all, :order => "created_at DESC", :limit => 20) end
Marca un comentario como inadecuado. Actualmente esta funcionalidad está desactivada.
# File app/controllers/comments_controller.rb, line 120 def report_abuse @comment = Comment.find(params[:id]) @comment.abuse_counter += 1 if @comment.save respond_to do |format| format.html { flash[:notice] = t('comments.abuse_thank_you2') redirect_to @comment.parent } format.js { render :update do |page| page.replace_html "abuse_#{@comment.id}", "<span>#{t('comments.abuse_thank_you')}</span>" end } end else respond_to do |format| format.html { flash[:error] = t('comments.abuse_unsaved') redirect_to @comment.parent } format.js { logger.info "El aviso no se ha guardado: #{@comment.errors.inspect}" render :nothing => true } end end end