Ok, I''ve got a nested resource, set up like so: map.resources :users, :has_one => :profile When I create a user, I''m using this route to go the new profile page: new_user_profile_path(@user) I''m my Profiles controller, I''m using a before_filter to determine the user: before_filter :load_user def load_user @user = User.find(params[:user_id]) end And in my "new" action: def new @profile = @user.profile.new end In my view, I have: form_for([@user, @profile]) do |f| But I get an error telling me that @user.profile is nil. The :user_id paramter is coming through fine, and @user has all the proper data in it. So is the problem with the scoped ActiveRecord call (@user.profile.new)? If I use @profile = Profile.new, I get an error telling me "user_profiles_path" in invalid (which I guess is being generated by the form_for). This is correct, since User should only have one Profile, not the plural "profiles." Anyone know what''s going on? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Have you tried simply using: form_for @profile do |f| If there is only one route to the profile (the nested one) I believe it will correctly build the path for you. On Feb 26, 7:06 pm, "Bryan M." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ok, I''ve got a nested resource, set up like so: > > map.resources :users, :has_one => :profile > > When I create a user, I''m using this route to go the new profile page: > > new_user_profile_path(@user) > > I''m my Profiles controller, I''m using a before_filter to determine the > user: > > before_filter :load_user > def load_user > @user = User.find(params[:user_id]) > end > > And in my "new" action: > > def new > @profile = @user.profile.new > end > > In my view, I have: > form_for([@user, @profile]) do |f| > > But I get an error telling me that @user.profile is nil. > The :user_id paramter is coming through fine, and @user has all the > proper data in it. So is the problem with the scoped ActiveRecord call > (@user.profile.new)? > > If I use @profile = Profile.new, I get an error telling me > "user_profiles_path" in invalid (which I guess is being generated by the > form_for). This is correct, since User should only have one Profile, not > the plural "profiles." > > Anyone know what''s going on? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AndyV wrote:> Have you tried simply using: > > form_for @profile do |f| >No such luck. It tries to route to "profile_path", which doesn''t exist. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Then it sounds like you want the more explicit version: form_for :profile, :url=>user_profile_path(@user, @profile), ... do | f| ... end On Feb 27, 6:02 pm, "Bryan M." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> AndyV wrote: > > Have you tried simply using: > > > form_for @profile do |f| > > No such luck. It tries to route to "profile_path", which doesn''t exist. > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AndyV wrote:> Then it sounds like you want the more explicit version: > > form_for :profile, :url=>user_profile_path(@user, @profile), ... do | > f| > ...Still no luck. Looking at my log, I can see that @user.profile.new (or @user.profile = Profile.new) is trying to grab a pre-existing profile relative to the user from the database. I cannot figure out how to instantiate a new profile on a user, and keep my nested routes intact. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry, I think I''ve been after the wrong end of the equation. With a has_one relationship you should be using @user.build_profile(...) On Feb 28, 10:42 pm, "Bryan M." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> AndyV wrote: > > Then it sounds like you want the more explicit version: > > > form_for :profile, :url=>user_profile_path(@user, @profile), ... do | > > f| > > ... > > Still no luck. Looking at my log, I can see that @user.profile.new (or > @user.profile = Profile.new) is trying to grab a pre-existing profile > relative to the user from the database. > > I cannot figure out how to instantiate a new profile on a user, and keep > my nested routes intact. > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---