On Tuesday, March 11, 2014 7:39:52 AM UTC-4, Frederick Cheung wrote:
>
>
>
> On Tuesday, March 11, 2014 10:27:36 AM UTC, Arun kant sharma wrote:
>>
>> My question is that why link_to method does not default to DELETE method 
>> when passed link is destroy_user_session_path as we know from routes 
>> what it should use. I don't have problem passing method: :delete but it 
>> feels redundant.
>> Also my bad. "Sign Up" should be "Sign out".
>>
>
> I think that would turn link_to from a very simple help which is just 
> generating some markup for you into a much more complicated ones that 
> interrogates routes in order find out what methods are acceptable.
>
> Fred
>

I agree with Fred and adding overhead to view helpers is generally not 
good.  There is also another problem with doing that.  The example you 
chose happens to have only one method mapped to the URI pattern.  This 
frequently isn't the case.  For example, suppose you have the following in 
your routes.db file:

resources :products

That's going to generate four routes for product_path, all having the url 
'/products/:id(.:format)'.  product_path/method:GET maps to one action. 
 product_path/method:PATCH maps to a different action, and so on (the other 
two are PUT and DELETE). 

If you do as you suggest and have the following statement:

<%= link_to "my example", product_path(1) %>

There would be no way the program could assign a method from the routes.db 
file since it would have four to choose from.

mike

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/1ace0be0-5176-4ed0-a411-3862ccfacedb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to