On Sep 30, 6:47 pm, Panda Beer <[EMAIL PROTECTED]>
wrote:
> Hello everybody,
>
> Here you can see my short code:
>
> # in routes.rb:
> map.resources :users
>
> # in users_controller.rb
> def new
>   @user = User.new
> end
>
> # in views/users/new.html.erb:
> <% form_for @user do |f| %>
>
> And that work very well. I would like to update the current route like
> this:
>
> # in routes.rb:
> map.resources :apps do |app|
>   app.resources :users
> end
>
> # in users_controller.rb
> def new
>   @user = User.new
>   @user.app_id = the_current_app.id
> end
>
> But after refresh, I got this error:
>
> NoMethodError in Users#new
>
> Showing users/new.html.erb where line #1 raised:
>
> undefined method `users_path' for #<ActionView::Base:0x20c4a34>
> Extracted source (around line #1):
>
> 1: <% form_for @user do |f| %>
>
> Is there a clean way to solve this error? (I believe it's possible to
> add a :url parameter in the form_for tag but I don't know if it's the
> best way.)
>
> Thanks a lot
> --
> Posted viahttp://www.ruby-forum.com/.

Try:

<% form_for @app, @user do |f| %>

Where your controller should look like

def new
  @app = App.find(params[:app_id])
  @user = User.new
  @user.app_id = params[:app_id]
end
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to