Nested Resources not working for me...

0 views
Skip to first unread message

Perry Smith

unread,
Oct 19, 2007, 5:24:20 PM10/19/07
to rubyonra...@googlegroups.com
This code works:

map.resources :feedbacks
map.resources :feedback_notes, :path_prefix =>
'/feedbacks/:feedback_id'

(this is in my config.rb file).

But this code does not:

map.resources :feedbacks do |feedback|
feedback.resources :feedback_notes
end

The error is:

undefined method `new_feedback_note_path' for
#<ActionView::Base:0x21bd380c>

The code in the view is:

<%= link_to 'New Note', new_feedback_note_path(@feedback) %>

I've been mucking around with this for half a day and can't figure out
what is wrong. I'm using edge rails last refreshed sometime this week.

Can anyone spot the errors of my ways?

Thanks,
pedz
--
Posted via http://www.ruby-forum.com/.

Michael Glaesemann

unread,
Oct 19, 2007, 7:20:22 PM10/19/07
to rubyonra...@googlegroups.com

On Oct 19, 2007, at 16:24 , Perry Smith wrote:

> undefined method `new_feedback_note_path' for
> #<ActionView::Base:0x21bd380c>
>
> The code in the view is:
>
> <%= link_to 'New Note', new_feedback_note_path(@feedback) %>

This should be new_feedback_feedback_note_path(@feedback)

Michael Glaesemann
grzm seespotcode net


Perry Smith

unread,
Oct 19, 2007, 8:01:20 PM10/19/07
to rubyonra...@googlegroups.com

Thanks. That got me past that obstacle.

Now, if I can press my luck, how should the form_for be done?

The scaffold generates:

<% form_for(@feedback_note) do |f| %>

But, that produces:

undefined method `feedback_notes_path' for
#<ActionView::Base:0x21b8efcc>

Michael Glaesemann

unread,
Oct 20, 2007, 10:34:31 AM10/20/07
to rubyonra...@googlegroups.com

On Oct 19, 2007, at 19:01 , Perry Smith wrote:

> The scaffold generates:
>
> <% form_for(@feedback_note) do |f| %>

script/generate scaffold doesn't produce forms that are useable for
nested resources (though maybe there's a flag that I'm unaware of). I
use the more traditional

form_for(:feedback_note,
:url => { :action => 'create', :feedback_id =>
@feedback.id }) do |f|

Scott A S

unread,
Oct 20, 2007, 11:27:00 AM10/20/07
to rubyonra...@googlegroups.com
have you tried <% form_for(@feedback, @feedback_note) do |f| %>

else this should work.
<% form_for @feedback_note, :url => feedback_feedback_note_path do |f|
%>

Gerjan Stokkink

unread,
Oct 20, 2007, 2:26:11 PM10/20/07
to rubyonra...@googlegroups.com
I think it should be:

<% form_for([@feedback, @feedback_note]) do |f| %>

Reply all
Reply to author
Forward
0 new messages