Ruby on rails Mongoid::Document子类签名表单_
我有一份Mongoid文档,如下所示:Ruby on rails Mongoid::Document子类签名表单_,ruby-on-rails,ruby-on-rails-3,mongoid,form-for,Ruby On Rails,Ruby On Rails 3,Mongoid,Form For,我有一份Mongoid文档,如下所示: class Index include Mongoid::Document end “索引”的两个子类如下: class PercentileRankIndex < Index end class SocialStockIndex < Index end class PercentileRankIndex“btn btn主要”%> “btn btn主要”%> 这可能不是最干净的方法,但仍然有效。我也希望看到有人提出更好的想
class Index
include Mongoid::Document
end
“索引”的两个子类如下:
class PercentileRankIndex < Index
end
class SocialStockIndex < Index
end
class PercentileRankIndex
我想为“PercentileRankIndex”创建一个表单,这是我现有的代码签名:
<%= form_for ([@index, @question]) do |f| %>
这条路径是:“百分位排名索引问题路径”
,因为@index是PercentileRankIndex的实例
然而,正确的路径是:“索引问题”
当使用适当的_type属性创建索引实例时,我的签名表单应该是什么样子的?我使用表单标签来避免这种情况:
<%= form_tag index_questions_path(:index_id => @index.id) do %>
<%= label_tag :name, "Name:" %>
<%= text_field_tag :name %>
<%= label_tag :weight, "Weight" %>
<%= text_field_tag :weight %>
<div class="actions">
<%= submit_tag "Save", :method => :post, :class => "btn btn-primary" %>
<%= link_to 'Back', index_questions_path, :class => "btn btn-primary" %>
</div>
<% end %>
@index.id)do%>
:post,:class=>“btn btn主要”%>
“btn btn主要”%>
这可能不是最干净的方法,但仍然有效。我也希望看到有人提出更好的想法