On Jul 14, 2011, at 1:58 PM, Leonel *.* wrote: > I have tried in so many ways and can't get it to work. I did something > yesterday that made the app have an redirect loop (too many redirects) > and it took me over an hour just to fix it. So I'm just going to start > all over again. > > My initial question had to do with other models but it's basically the > same. I need to do the same for several models. This what I have now. > > There are two models: Company and User. > company has_many :users > user has_one :company > > routes.rb > resources :companies > resources :users > resources :companies do > resources :users > end > > Those routes allow me to do this: > companies/2/users/new > > Which is good, but once I submit the form, the app seems to forget the > company_id. >
You have both a regular route and a nested route for your users. Make sure your form is submitting to the nested route. It should look something like (depending on your variable names): form_for [@company, @user] do |f| Without the company your form will post to /users and the company id will not be passed. Juan Alvarado > -- > 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@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.