views:

14

answers:

3

Here's the page template I've got:

<h1>Editing user</h1>

<% form_for(@user) do |f| %>
    <%= f.error_messages %>
    <p>
        <%= f.label :forename %><br />
        <%= f.text_field :forename %>
    </p>
    <p>
        <%= f.label :surname %><br />
        <%= f.text_field :surname %>
    </p>
    <p>
        <%= f.label :address %>
        <%= f.text_field :address %>
    </p>
    <p>
        <%= f.label :postcode %>
        <%= f.text_field :postcode %>
    </p>
    <p>
        <%= f.label :contact_number %>
        <%= f.text_field :contact_number %>
    </p>
<% end %>

<%= link_to 'Show', @user %> |
<%= link_to 'Back', users_path %>

The controller is actually sub-typed from the AdminController as there's a separate section as the following class declaration shows:

class Admin::UsersController < ApplicationController

with the edit method as follows:

def edit
    @user = User.find(params[:id])
end

With the error as follows:

undefined method `user_path' for #<ActionView::Base:0x104369fe8>

and the following in my routes:

map.namespace(:admin) do |admin|
    admin.resources :pages
    admin.resources :treatments
    admin.resources :users
    admin.resources :finances
end

So I'm a bit stuck, because it's the form_for(@user) that's doing it. I've seen this before but have no idea how to diagnose it unfortunately.

A: 

Doesn't the name-spacing change the named paths so maybe to need to be explicit it in the form like this?

form_for (@user, :url => admin_user_path) do |f|
bjg
This will work not work for edit scenarios as the URL will be different.
KandadaBoggu
@KandadaBoggu. I understand that but then you could use `edit_admin_user_path` for that case, no? But I like your answer better anyway
bjg
Yes, you are correct. You have to have additional code to check the state of the object and set the url accordingly.
KandadaBoggu
+1  A: 

Since you are using a name spaced routes, you have to specify the name space in the form_for invocation.

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

Refer to the documentation for more details.(Hint: Read the end of the Resource-oriented style section)

KandadaBoggu
A: 

For the namespace you are using....the link would be

<% form_for @user, edit_admin_user_path(@user.id) do |f|%>
     .....
<% end %>

Do a rake routes to look at how routes look like for a namespaced controller

Suman Mukherjee