I got a routing error when trying to create a note object from inside a property object: Routing Error property_url failed to generate from {:action=>"show", :controller=>"properties", :id=>nil}, expected: {:controller=>"properties", :action=>"show"}, diff: {:id=>nil} Here''s what''s going on: # Show action from the properties controller def show @property = Property.find(params[:id]) @note = @property.notes.new respond_to do |format| format.html format.xml { render :xml => @property } end end # Create action from the notes controller def create @note = Note.new(params[:note]) @note.user_id = current_user.id respond_to do |format| if @note.save flash[:notice] = ''Note was successfully created.'' format.html { redirect_to property_path @note.property_id } format.xml { render :xml => @note, :status => :created, :location => @note } else format.html { render :action => "new" } format.xml { render :xml => @note.errors, :status => :unprocessable_entity } end end end # show.html.erb for properties <% form_for @note do |f| %> <%= f.error_messages %> <p> <%= f.label ''New note:'' %><br /> <%= f.text_area :text %> </p> <p> <%= f.submit ''Save note'' %> </p> <% end %> The form displays correctly, but gives a routing error when saving. I''m not sure what the error is trying to tell me. This works fine from the console, insofar as I can call "@note=@property.note.new; @note.save" and have it save successfully. How can I do it from a view? Ultimately, the goal is to populate notes linked to the property_id without resorting to either hidden fields (insecure) or session variables. I thought a form was the way to go, but I''m really stuck. -- "Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks"
On Nov 16, 9:46 am, "Todd A. Jacobs" <tjacobs-sndr- b4f...-S/bPM5e9wgfNLxjTenLetw@public.gmane.org> wrote:> The form displays correctly, but gives a routing error when saving. I''m > not sure what the error is trying to tell me.The error is telling you that you called property_path(nil) - for whatever reason @note.property_id isn''t set. Fred> > This works fine from the console, insofar as I can call > "@no...-33AYZwtzeUmtJjIuiQdAsAIxwlB7+PcL@public.gmane.org; @note.save" and have it save successfully. > How can I do it from a view? > > Ultimately, the goal is to populate notes linked to the property_id > without resorting to either hidden fields (insecure) or session > variables. I thought a form was the way to go, but I''m really stuck. > > -- > "Oh, look: rocks!" > -- Doctor Who, "Destiny of the Daleks"
On Mon, Nov 16, 2009 at 04:30:23AM -0800, Frederick Cheung wrote:> The error is telling you that you called property_path(nil) - for > whatever reason @note.property_id isn''t set.Thanks. I had suspected as much, but still found the error rather opaque. Still, I don''t understand *why* it''s being unset, since I''m setting it explicitly in the property controller. Rather than guessing at why, though, what I''d really like is a reliable mechanism to populate @note.property_id from the properties controller--or perhaps from the notes controller if I can somehow get at the referrer. Is there a way to call Note.new with arbitrary values? -- "Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks"
On Nov 16, 12:45 pm, "Todd A. Jacobs" <tjacobs-sndr- b4f...-S/bPM5e9wgfNLxjTenLetw@public.gmane.org> wrote:> On Mon, Nov 16, 2009 at 04:30:23AM -0800, Frederick Cheung wrote: > > The error is telling you that you called property_path(nil) - for > > whatever reason @note.property_id isn''t set. > > Thanks. I had suspected as much, but still found the error rather > opaque. Still, I don''t understand *why* it''s being unset, since I''m > setting it explicitly in the property controller. >You''re not really - you''re setting it in the new method, but not in the create one (or are you using the nested attributes stuff) ? Fred> Rather than guessing at why, though, what I''d really like is a reliable > mechanism to populate @note.property_id from the properties > controller--or perhaps from the notes controller if I can somehow get at > the referrer. > > Is there a way to call Note.new with arbitrary values? > > -- > "Oh, look: rocks!" > -- Doctor Who, "Destiny of the Daleks"
On Mon, Nov 16, 2009 at 05:46:57AM -0800, Frederick Cheung wrote:> You''re not really - you''re setting it in the new method, but not in > the create one (or are you using the nested attributes stuff) ?If I call @note = @property.notes.new from the console, it properly populates the property_id and passes it onto the note object. I''ve been trying this different ways, and maybe I don''t really understand what''s being called when I do it via the web. At present, I''m calling this from the properties controller, rather than the notes controller, in the show action (which is where I have embedded the New Note form). I''m not sure how to do it in notes.new or notes.create, since I don''t understand how to propogate the parent ID to the notes controller from the property controller that way. Can you offer a practical snippet for me to try? -- "Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks"
Routing Error No route matches "/object1/object2/392" with {:method=>:get} object2 имеет view - object2.rhtml.erb and controller - object1.rb. Which contains a method: def object2 @user = ObjectProfile.find(params[:id]) end help solve the problem please. I think the problem is routing.But I do not know how to solve it. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Dec 6, 2009 at 8:16 AM, procedureBSD-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <procedurebsd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Routing Error > > No route matches "/object1/object2/392" with {:method=>:get} > > object2 имеет view - object2.rhtml.erb and controller - object1.rb. > Which contains a method: > > def object2 > @user = ObjectProfile.find(params[:id]) > end > > > help solve the problem please. I think the problem is routing.But I do > not know how to solve it.If object2 is a method of Object1Controller, other than the resource''s methods, you need to define the route on your routes.rb file. If you haven''t read the routing guide[1], I STRONGLY recommend you to do that before continue. Hope it helps. Cheers. [1]http://guides.rubyonrails.org/routing.html -- Leonardo Mateo. There''s no place like ~ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.