what is the right 'rails' way to add a link_to a new custom method
Posted
by
jpwynn
on Stack Overflow
See other posts from Stack Overflow
or by jpwynn
Published on 2011-02-19T07:04:00Z
Indexed on
2011/02/19
7:25 UTC
Read the original article
Hit count: 223
ruby-on-rails
|urlhelper
We're adding a new method 'delete_stuff' to the WidgetsController of a scaffolded app.
in routes we added match 'widget/delete_stuff/:id' => 'widgets#delete_stuff'
I CAN manually create html (GET) links like
<a href="/widget/delete_stuff/<% widget.id %>">My Custom Delete Stuff</a>
But that's bad on so many levels (uses GET instead of DELETE, doesn't permit a CONFIRM dialog, isnt DRY, etc)
Problem is I can't figure out how to use the url helpers for a custom method... trying to do something like this:
<% link_to 'DeleteStuff', @widget, :confirm => 'Are you sure?', :method => :delete %>
But that just gets ignored when the html is rendered.
I'm clearly missing something fundamental on how to use link_to, any help will be appreciated!
Cheers, JP
© Stack Overflow or respective owner