我有以下型号:如何建立一个嵌套形式
class Poll < ActiveRecord::Base
has_many :poll_votes, :dependent => :destroy
has_many :poll_options, :dependent => :destroy
class PollOption < ActiveRecord::Base
belongs_to :poll
has_many :poll_votes, :dependent => :destroy
class PollVote < ActiveRecord::Base
belongs_to :user
belongs_to :poll
belongs_to :poll_option
我试图做的是建立输出一个投票形式和它的选项。允许用户选择一个选项并提交投票。我正在努力创建表单标签。
这是我有:
<%= form_for(@poll, :url => new_poll_poll_vote_path, :remote => true) do |f| %>
<% @poll.poll_options.each do |poll_option| %>
<div class="row clearfix" id="poll_option_<%=poll_option.id%>">
<div class="inputRadio">
<%= radio_button("poll", "poll_votes", poll_option.id, :class => 'pollVote') %>
</div>
<div class="inputLabel">
<%= poll_option.title %>
</div>
</div>
<%= f.submit :class => 'button positive', :value => 'Vote' %>
<% end %>
routes文件
resources :polls do
resources :poll_votes
end
建议/建议我如何能建立表单,让用户投票? thxs
不是一个真正的答案,但看看这个http://railscasts.com/episodes/196-nested-model-form-part-1(和系列中的下一个),看看Ryan Bates解释过的非常相似的东西。 – Dogbert
谢谢我已经很接近但不够类似于我解决这个 – AnApprentice