dewie
December 10, 2007, 12:07pm
1
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.
dewie
December 10, 2007, 12:32pm
2
Try:
form_for([:admin, @cupcake ])
dewie
December 10, 2007, 12:45pm
3
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.
dewie
December 10, 2007, 12:53pm
4
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)
dewie
December 10, 2007, 12:58pm
6
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.
dewie
December 10, 2007, 1:00pm
7
Straight from the docs (last entry under “Relying on record
identification”):
And for namespaced routes, like admin_post_url:
<% form_for([:admin, @post ]) do |f| %>
…
<% end %>
dewie
December 10, 2007, 1:05pm
8
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…
dewie
December 10, 2007, 1:09pm
9
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)
dewie
December 10, 2007, 1:12pm
10
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.
dewie
December 10, 2007, 1:12pm
11
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.
dewie
December 10, 2007, 1:08pm
12
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’.