Map.namespace, rake routes yields no POST URLs

routes.rb

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

rake routes

cupcakes GET /cupcakes
formatted_cupcakes GET /cupcakes.:format
POST /cupcakes
POST /cupcakes.:format

That said, what the heck goes here:

form_for(:cupcake, @cupcake, xxx_url) # ???

Calling create_admin_cupcake_url yields…

undefined local variable or method ‘create_admin_cupcake_url’

Additionally, calling form_for(@cupcake) yields…

undefined method ‘cupcake_path’

Finally, I’ve also tried…

form_for(:cupcake, @cupcake, admin_cupcake_url, :method => :put)

Which points to this URL:
/admin/cupcakes/1/edit

And gives me this view:

Unknown action
No action responded to 1

Routing and URL helpers (what do I use when?) have been the biggest
barrier to creating a RESTful app.

I’ve watched the Railscasts video and read the 2.0 release notes, and
yes, the new stuff sure looks tasty, but it’s useless if I can’t get it
to work.

Try:

form_for([:admin, @cupcake])

Gerjan S. wrote:

Try:

form_for([:admin, @cupcake])

Wow. It worked. Where’s the documentation for that?

Thank you so much, Gerjan. You’re a life-saver.

form_for(:cupcake, @cupcake, admin_cupcake_url, :method => :put)

By the way, that didn’t work because you forgot to supply the cupcake id
to the admin_cupcake_url helper. It should’ve been:

form_for(:cupcake, @cupcake, admin_cupcake_url(@cupcake), :method =>
:put)

Daniel W. wrote:

Gerjan S. wrote:

Try:

form_for([:admin, @cupcake])

Wow. It worked. Where’s the documentation for that?

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000907

Gerjan S. wrote:

Daniel W. wrote:

Wow. It worked. Where’s the documentation for that?

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000907

Hmm, the only hint I see there is the parameter name,
record_or_name_or_array, so I’m not sure how you deduced the solution,
but whatever works. :slight_smile:

Straight from the docs (last entry under “Relying on record
identification”):

Gerjan S. wrote:

form_for(:cupcake, @cupcake, admin_cupcake_url, :method => :put)

By the way, that didn’t work because you forgot to supply the cupcake id
to the admin_cupcake_url helper. It should’ve been:

form_for(:cupcake, @cupcake, admin_cupcake_url(@cupcake), :method =>
:put)

Nay. Although, true, in my example I didn’t pass @cupcake to the _url
method, I have indeed tried it, and the result is the same as if I did
not pass it.

form_for(:cupcake, @cupcake, admin_cupcake_url(@cupcake), :method =>
:put)

Yields this URL for form:action…

/admin/cupcakes/1/edit

With no additional field for the HTTP method.

Again the view is the weird:

Unknown action
No action responded to 1

Straight from the docs (last entry under “Relying on record
identification”):

Sure enough. That’s what I get for scanning through the documentation.
Good to know it’s there… :slight_smile:

Daniel W. wrote:

Nay. Although, true, in my example I didn’t pass @cupcake to the _url
method, I have indeed tried it, and the result is the same as if I did
not pass it.

form_for(:cupcake, @cupcake, admin_cupcake_url(@cupcake), :method =>
:put)

Hmm, try this:

form_for(:cupcake, @cupcake, :url => admin_cupcake_url(@cupcake),
:method => :put)

Daniel W. wrote:

Daniel W. wrote:

Gerjan S. wrote:

form_for(:cupcake, @cupcake, admin_cupcake_url, :method => :put)

Wow, I want to stab myself. Simple, simple mistakes:

form_for(:cupcake, @cupcake, :url => admin_cupcake_path(@cupcake), :html
=> { :method => :put })

I swear I’m not new to this – I just get excited and rush through
things.

Gerjan S. wrote:

Daniel W. wrote:

Nay. Although, true, in my example I didn’t pass @cupcake to the _url
method, I have indeed tried it, and the result is the same as if I did
not pass it.

form_for(:cupcake, @cupcake, admin_cupcake_url(@cupcake), :method =>
:put)

Hmm, try this:

form_for(:cupcake, @cupcake, :url => admin_cupcake_url(@cupcake),
:method => :put)

LOL. I was moments too late. Thanks again Gerjan! You rock. :slight_smile:

Daniel W. wrote:

Gerjan S. wrote:

form_for(:cupcake, @cupcake, admin_cupcake_url, :method => :put)

This is actually the correct form:

form_for(:cupcake, @cupcake, admin_cupcake_url(@cupcake), :html => {
:method => :put })

Even so, I still get the same form:action URL (edit instead of update)
and the rendered view complains of an unknown action ‘1’.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs