Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Answer < ActiveRecord::Base
- has_many :comments, dependent: :destroy
- belongs_to :question
- attr_accessible :anonymous, :answer, :commenter, :votes, :comments_attributes
- accepts_nested_attributes_for :comments
- end
- <%= form_for([@question, @answer]) do |f| %>
- <p>
- <%= f.label :answer %>
- <%= f.text_area :answer, :cols => "50", :rows => "30"%>
- </p>
- <p>
- <%= check_box_tag(:anonymous)%>
- <%= label_tag(:anonymous, "Anonymous")%>
- </p>
- <p>
- <%= f.submit "Submit Answer" %>
- </p>
- <% end %>
- def create
- @answer = @question.answers.new(params[:answer])
- if @answer.anonymous == true
- @answer.commenter = "Anonymous"
- else
- @answer.commenter = current_user.username
- end
- if @answer.save
- redirect_to question_path(@question)
- else
- redirect_to questions_path
- end
- end
- f.check_box :anonymous
- <%= check_box_tag(:anonymous)%>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement