Why do I get error like this?
undefined method `community_topics_path' for #<#<Class:0x00000009d79098>:0x00000009d70a38>
Extracted source (around line #1):
1: <%= form_for @community_topic, :html => { :class => 'form-horizontal' } do |f| %>
2: <div class="control-group">
3: <%= f.label :community_id, :class => 'control-label' %>
4: <div class="controls">
rake routes shows I use ‘to_param’ for community’s id but I haven’t defined :community_id at all in my routes.rb. I wonder why rake routes shows this :community_id. Is that probably because I use ‘to_param’ for my community model?? That’s why it automatically detect that and replace :id to :community_id?
new_community_topic GET /communities/:community_id/topic/new(.:format) community_topics#new
routes.rb
resources :communities do
resources :community_topics, :path => "topic", :as => :'topic'
end
views/communities/_form.html.erb
<%= form_for @community_topic, :html => { :class => 'form-horizontal' } do |f| %>
.......
<div class="form-actions">
<%= f.submit nil, :class => 'btn btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
community_topic_path, :class => 'btn' %>
</div>
<% end %>
Updated!!!
**rake routes | grep community_topic
community_topic_index GET /communities/:community_id/topic(.:format) community_topics#index
POST /communities/:community_id/topic(.:format) community_topics#create
new_community_topic GET /communities/:community_id/topic/new(.:format) community_topics#new
edit_community_topic GET /communities/:community_id/topic/:id/edit(.:format) community_topics#edit
community_topic GET /communities/:community_id/topic/:id(.:format) community_topics#show
PUT /communities/:community_id/topic/:id(.:format) community_topics#update
DELETE /communities/:community_id/topic/:id(.:format) community_topics#destroy
As you are using nested routing then you have to pass and
communityintoform_for:upd: Or
@community_topic.communityin case you ain’t set@community.You can watch this episode of RailsCasts to fully understand nested resources. Episode use Rails 2 for examples but you should understand the conception.