Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. class Answer < ActiveRecord::Base
  2. has_many :comments, dependent: :destroy
  3. belongs_to :question
  4. attr_accessible :anonymous, :answer, :commenter, :votes, :comments_attributes
  5. accepts_nested_attributes_for :comments
  6. end
  7.  
  8. <%= form_for([@question, @answer]) do |f| %>
  9. <p>
  10. <%= f.label :answer %>
  11. <%= f.text_area :answer, :cols => "50", :rows => "30"%>
  12. </p>
  13. <p>
  14. <%= check_box_tag(:anonymous)%>
  15. <%= label_tag(:anonymous, "Anonymous")%>
  16. </p>
  17. <p>
  18. <%= f.submit "Submit Answer" %>
  19. </p>
  20. <% end %>
  21.  
  22. def create
  23. @answer = @question.answers.new(params[:answer])
  24. if @answer.anonymous == true
  25. @answer.commenter = "Anonymous"
  26. else
  27. @answer.commenter = current_user.username
  28. end
  29. if @answer.save
  30. redirect_to question_path(@question)
  31. else
  32. redirect_to questions_path
  33. end
  34. end
  35.  
  36. f.check_box :anonymous
  37.  
  38. <%= check_box_tag(:anonymous)%>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement