Guest User

Untitled

a guest
Apr 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. class PostsController < SiteController
  2.  
  3. def update
  4. if @type == 'Answer'
  5. @post = Answer.find_by_parent_id(params[:id])
  6. else
  7. @post = Message.find(params[:id])
  8. end
  9.  
  10. respond_to do |format|
  11. else
  12. # post attributes
  13. @post.attributes = params[:post]
  14.  
  15. if @type == 'Answer' && params[:post] && params[:post][:addressee_id]
  16. addressee = @post.message.site.addressees.find_by_id(params[:post][:addressee_id])
  17. @post.addressee = addressee if addressee
  18. end
  19.  
  20. ... resource stuff ...
  21.  
  22. # need to resource.valid? because its already saved above
  23. if @post.save && @post.resources.all?{|r| r.valid?}
  24. flash[:unpublished_post] = @post.id if !@post.published && @post.author.is_a?(AnonymousAuthor)
  25. flash[:notice] = "#{@type} updated."
  26. format.html { redirect_to( ( @type == 'Message' ? message_path(:id => @post.id) : message_path(:id => @post.parent_id) ) ) }
  27. else
  28. format.html do render :action => 'edit'
  29. initialize_resources
  30. set_form_params
  31. end
  32. format.js do
  33. render :nothing => true, :status => 500
  34. end
  35. end
  36.  
  37. end
  38.  
  39. end
  40. rescue AuthError
  41. msg = "You don't have the rights to edit that post. Your attempt has been logged."
  42. respond_to do |wants|
  43. wants.html { flash[:notice] = msg; redirect_back_or_default(message_path(:id => message)) }
  44. wants.js { render :text => msg, :status => 400 }
  45. end
  46. end
  47. end
Add Comment
Please, Sign In to add comment