When you have a namespace in your routes.rb like this:

  map.namespace :admin do |admin|
    admin.resources :users
  end

And you like to have a form like this:

<% form_for(@user) do |f| %>
  <%= f.error_messages %>

Change the form_for in this and you’re good to go!

<% form_for([:admin, @user]) do |f| %>
  <%= f.error_messages %>

This might save you some time. ;-)

5 Responses to “Namespace route and form_for method”
  1. Thx for the tip!
    I was replacing the form_for(@user) with form_for(@user, :url => admin_user_path(@user))…
    Your way is shorter and cleaner.

    Geoff

  2. celio motta says:

    Great!!! Thank you!!!

  3. thanks, you saved my day

  4. Thank you for the fast tip!!

  5. Thanks! That’s a lot easier than how I was doing it.

Leave a Reply