Reputation: 73
I saw similar examples here. But it just doesn't work for me. I want to create/submit an activity for post. There are several days under a post. And an activity is under a specific date. See models below.
Models:
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
Routes:
resources :posts do
resources :dayinposts do
resources :activitys
end
end
rake routes
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
show.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 %>
error
undefined method `post_dayinpost_activities_path' for #<#<Class:0x40cb6d8>:0x40c9890>
But I have saw it in the rake routes... thanks in advance!
Upvotes: 1
Views: 359
Reputation: 107718
The correct pluralization for "activity" is "activities".
In your config/routes.rb
you have "activitys", which is wrong.
Upvotes: 1