Form_for problem

Greetings All,

I have an interesting issue that I can only assume is me doing something
dumb.

======
I have the following route defined

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

======
I have a form:

  • form_for @user, :url=>admin_user_path do |f|

======
and an rspec

require ‘spec_helper’

describe “/admin/users/edit.html.haml” do

it “renders edit admin user form” do
@user = mock_model(User)#Factory.create(:valid_user)
assigns[:user] = @user
render
end
end

======
it produces the following error when ran

ActionView::TemplateError: admin_user_url failed to generate from
{:action=>“show”, :controller=>“admin/users”} - you may have ambiguous
routes, or you may need to supply additional parameters for this route.
content_url has the following required parameters: [“admin”, “users”,
:id]

  • are they all satisfied?
    On line #1 of app/views/admin/users/edit.html.haml

    1: - form_for @user, :url=>admin_user_path do |f|
    2: %p

    (eval):16:in `admin_user_path’

========

This form works when I fire up WEBrick and navigate to it manually.

========

What am I doing wrong?

Brandon

Okay I figured out my error.

I needed to specify my form_for like:

  • form_for [:admin, @user] do |f|

This is obviously cleaner. It is strange that a running rails app would
accept this while rspec rendered view would not. Anyway, I’m glad that
rspec
didn’t accept this since the way i’m using it now is cleaner.

Thanks,
Brandon