我有一个Posts模型,其中有许多多种语言的帖子。这有点不标准,但为了说明:
class Post < ActiveRecord::Base
has_one :eng_post, :dependent => :destroy # <-- HAS_ONE!
accepts_nested_attributes_for :eng_post, :allow_destroy => true
end
即一个帖子有一个EngPost。而 EngPost 在模型中被定义为:
class EngPost < ActiveRecord::Base
belongs_to :post
has_many :eng_comments, :dependent => :destroy
accepts_nested_attributes_for :eng_comments, :allow_destroy => true
attr_accessible :eng_comments_attributes
end
最后,eng_comments 模型是:
class EngComment < ActiveRecord::Base
belongs_to :eng_post, :foreign_key => "eng_post_id"
end
routes.rb 定义:
resources :posts do
resource :eng_posts
end
resource :eng_post do
resources :eng_comments
end
resources :eng_comments
问题 - 无法使用eng_comments 呈现帖子,我试过:
<% form_for ([@post, @post.eng_post, @post.eng_post.eng_comments.build]) do |f| %>
并尝试:
<% form_for @comment do |f| %>
这会导致错误
undefined method `post_eng_post_eng_comments_path' for #<#<Class:0x000000067de2a8>:0x000000067c4498>
谢谢。