Hello. So solved some error with just replacing path method with calling :action=>... But I''m curious why in absolutely same in first case _path worked perfect, in second it causer an error which is solved just by changing syntax (but 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 {:action=>"delete_answer", :controller=>"tests", :id=>nil}) Started DELETE "/tests/150/create_answer?key_id=905&url=%2Ftests%2F150%2Fdelete_answer" for 127.0.0.1 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 of what is going on) works fine. ? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/8eouGU9Pm9QJ. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2013-Mar-18 10:12 UTC
Re: Difference between _path and :action => ''some_method''
On Monday, March 18, 2013 8:33:15 AM UTC, Barry wrote:> > Hello. So solved some error with just replacing path method with calling > :action=>... > But I''m curious why in absolutely same in first case _path worked perfect, > in second it causer an error which is solved just by changing syntax (but > 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 > {:action=>"delete_answer", :controller=>"tests", :id=>nil}) > >You haven''t said what the route is, but it would appear that you''ve made it a member route of a collection: this is an action that does something with 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 make any sense to rails (although of course it doesn''t know if you then use the id parameter or not) Fred> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/j3ol6ogOJqAJ. For more options, visit https://groups.google.com/groups/opt_out.