The problem seems so simple, but I just can’t seem to fix it. I must be missing something obvious, but would really appreciate any help at all!
Error message that appears:
undefined method `discussions_path' for #<#<Class:0x000001032e90d8>:0x000001030f1168>
Routes file:
resources :forums do
resources :discussions
end
Discussions/_form.html.erb file:
<%= form_for [@forum, @discussion] do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p><%= f.submit "Submit" %></p>
<% end %>
Discussions controller new action:
def new
@forum = Forum.find_by_permalink(params[:id])
@discussion = Discussion.new
end
This is full error I’m now getting (in Terminal):
Started GET "/forums/general-chat/discussions/new" for 127.0.0.1 at 2012-04-14 18:35:28 +0100
Processing by DiscussionsController#new as HTML
Parameters: {"forum_id"=>"general-chat"}
Forum Load (1.6ms) SELECT "forums".* FROM "forums" WHERE "forums"."permalink" IS NULL LIMIT 1
Rendered layouts/_content_full_start.html.erb (0.0ms)
Rendered discussions/_form.html.erb (574.4ms)
Rendered discussions/new.html.erb within layouts/application (575.9ms)
Completed 500 Internal Server Error in 581ms
For nested resources you need to pass an array in to
form_forwith the forum and discussion, e.g. set@forumin your controller, and then in the view use:From the rails docs: