Forum: Ruby on Rails Difference between _path and :action => 'some_method'

E1f877eccccc9e714b4d4fe03917f2a7?d=identicon&s=25 Barry (Guest)
on 2013-03-18 09:34
(Received via mailing list)
Hello. So solved some error with just replacing path method with calling
But I'm curious why in absolutely same in first case _path worked
in second it causer an error which is solved just by changing syntax
not the sence of what is happening)
First case:

<%= form_for @answer, {:url => create_answer_test_path(@test), :html =>
{:id=>"form_#{@key.position}"}, :remote=>true}

worked with no problem

<%= button_to '-', {:url=>delete_answer_test_path(@test)},
:method=>:delete, :remote =>true %>

Caused several types of errors:

ActionController::RoutingError (No route matches
:controller=>"tests", :id=>nil})

Started DELETE
for at 2013-03-18 12:08:36 +0400 (??? for some reason started
previous method and 'delete_answer' was just in server call)

But when I replaced it with {:controller=>'tests', :action =>
'delete_answer'} (which is basically just another way of syntax, but not
what is going on) works fine.

81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2013-03-18 11:13
(Received via mailing list)
On Monday, March 18, 2013 8:33:15 AM UTC, Barry wrote:
You haven't said what the route is, but it would appear that you've made
a member route of a collection: this is an action that does something
a specific instance of your Test class. What this error is saying is
that  @test is apparently unsaved so doesn't have an id, which doesn't
any sense to rails (although of course it doesn't know if you then use
id parameter or not)

Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.