Guest User

Untitled

a guest
Aug 1st, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. unable to display validation error from a partial form
  2. %html
  3. %head
  4. %title= @post.title
  5. %body
  6. %h2 Create Comments:
  7. = form_for([@post, @post.comments.build]) do |f|
  8. - if @post.errors.any? # <--- Unsure what to do here..
  9. #error_explanation
  10. %h2
  11. = pluralize(@post.errors.count, "error")
  12. prohibited this cart from being saved:
  13. %ul
  14. - @post.errors.full_messages.each do |msg|
  15. %li= msg
  16. = f.label :Name
  17. %br
  18. = f.text_field :name
  19. %br
  20. %br
  21. = f.label :Text
  22. %br
  23. = f.text_area :text
  24. %br
  25. %br
  26. = f.submit
  27.  
  28. def create
  29. @post = Post.find(params[:post_id])
  30.  
  31. @comment = @post.comments.build(params[:comment])
  32. respond_to do |format|
  33. if @comment.save
  34. format.html { redirect_to @post }
  35. else
  36. format.html { redirect_to @post }
  37. end
  38. end
  39. end
  40.  
  41. %html
  42. %head
  43. %title= @post.title
  44. %body
  45. %strong Author name:
  46. = @post.author_name
  47. %br
  48. %br
  49. %strong Title:
  50. = @post.title
  51. %br
  52. %br
  53. %strong Email:
  54. = @post.email
  55. %br
  56. %br
  57. %strong Description:
  58. = @post.description
  59.  
  60. %h2 Comments for this Post:
  61.  
  62. = render :partial => @post.comments
  63.  
  64. = render :partial => "comments/form"
  65.  
  66. if @comment.save
  67. format.html { redirect_to @post }
  68. else
  69. render :action => "new"
  70. end
Add Comment
Please, Sign In to add comment