【发布时间】:2015-11-12 01:47:08
【问题描述】:
我有这个应用程序,我正在尝试使用谱系表添加狗家庭关系(狗 A 是狗 B 的兄弟姐妹)。但是,我在制作能够实现这一目标的表单时遇到问题。 This is how my form looks like at the moment.
您可以在狗的个人资料页面中看到表单加载,用户可以选择他的一只狗并创建关系。这是从views/pedigrees/_form.html.erb 在views/dog/show.html.erb 页面中呈现的表单代码:
<%= form_for(@pedigree, url: new_pedigree_path, html: {method: :post}) do |d| %>
Select your dog:
<%= d.collection_select(:dog_id, @dogs,:id, :dname, :prompt => "Select your dog") %>
<br>
Select your dog relation to the dog from this profile:
<%= select_tag(:relation_name, options_for_select([['Sibling', 1], ['Parent', 2], ['Grandparent', 3],
['Great-grandparent', 4], ['Child', 5], ['Grandchild', 6], ['Great-grandchild', 7]])) %>
<br>
<%= d.submit 'Add Relation' %>
<% end %>
我在生成的源代码中得到以下内容:
<form class="new_pedigree" id="new_pedigree" action="/pedigree/new" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="authenticity_token" value="RYOjO10gUvVUQkRaqyum8wB0VJrTwm8MQ6WxIJ3eM4ukP2zHHDECFaT8UUYytSv2OGBUGhvK4k3fwOt+xDfabA==" />
当我单击按钮提交表单时,我收到以下错误:
Missing template pedigree/new, application/new with...
如何操作 form_for 以便在不需要新的表单模板的情况下呈现谱系关系?以及如何在按下提交按钮时调用#create 方法?谢谢。
【问题讨论】:
标签: ruby-on-rails forms ruby-on-rails-4