[问题] sub model的view以及controller储存方法

楼主: GrantHill33 (葛兰特希尔)   2014-08-20 13:58:54
新手一枚 继续发问
有个MODEL是问题
每个问题可以有多个答案
model长这样
class Question < ActiveRecord::Base
has_many :answers
end
class Answer < ActiveRecord::Base
belongs_to :question
end
想请问在Question的show page上要怎么使用form来让使用者填写answer
以及在接收post的controller里怎么储存这笔资料进去DB
假设form长这样
<%= form_for([@question, @answer], url: answers_new_path,
html: { method: :post }) do |f| %>
<%= f.hidden_field :question_id, :value => @question.id %>
<%= f.text_area :content, autofocus: true %>
<% end %>
controller action那边要怎么接收参数并储存到DB呢?
谢谢~

Links booklink

Contact Us: admin [ a t ] ucptt.com