2013-04-15 106 views
2

簽名我有一個Mongoid文檔:的form_for爲Mongoid ::文檔子

class Index 
    include Mongoid::Document 

end 

和兩個子類 '指數' 爲:

class PercentileRankIndex < Index 

end 

class SocialStockIndex < Index 


end 

我想創建一個的form_for說「PercentileRankIndex 」,這是我現有的代碼簽名:

<%= form_for ([@index, @question]) do |f| %> 

都到路線:'percentile_rank_index_questions_path'爲@index是Percen實例tileRankIndex。

但是它存在正確的路線是:'index_questions'

應該如何我的form_for簽名的樣子,以便在指數實例與適當的_type屬性產生的?

回答

0

我用的form_tag要解決這種情況:

<%= 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 %> 

這可能不是最徹底的方法,但仍然有效。希望看到有人提出更好的想法。