1

我在这里看到了类似的例子。但这对我不起作用。我想为帖子创建/提交活动。有几天下一个帖子。并且活动在特定日期下。请参阅下面的模型。

楷模:

class Post < ActiveRecord::Base
  has_many :dayinposts
  has_many :activitys, :through => :dayinposts
end

class Dayinpost < ActiveRecord::Base
  belongs_to :post
  has_many :activitys
end

class Activity < ActiveRecord::Base
  belongs_to :dayinpost
end

路线:

resources :posts do
  resources :dayinposts  do
resources :activitys
  end 
end

耙路线

post_dayinpost_activitys GET /posts/:post_id/dayinposts/:dayinpost_id/activitys(.:format)          activitys#index
                         POST /posts/:post_id/dayinposts/:dayinpost_id/activitys(.:format)          activitys#create

显示.html.erb

<% @post.dayinposts.each do |dayinpost| %>

<% dayinpost.activitys.each do |activity| %>
  <p>
  <b>Action:</b>
  <%= activity.action %>
  </p>
<% end %>

<%= form_for([@post, dayinpost, dayinpost.activitys.build]) do |f| %>
  <div class="field">
  <%= f.label :action %><br />
  <%= f.text_field :action %>
  </div>

<div class="actions">
<%= f.submit %>
</div>
<% end %>

<% end %>

错误

undefined method `post_dayinpost_activities_path' for #<#<Class:0x40cb6d8>:0x40c9890>

但我在 rake 路线中看到了它......在此先感谢!

4

1 回答 1

1

“活动”的正确复数形式是“活动”。

在你的config/routes.rb你有“活动”,这是错误的。

于 2012-07-02T04:59:21.593 回答