Re: Routing error (route not found) but only for destroy action.

Frederick Cheung
Mon, 22 Aug 2011 12:28:17 -0000

On Aug 22, 12:48 pm, Stefano
<stefano....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> Hi guys
>
> I have many different models and I want to reuse the same code for the
> delete button.
> So in my helper i have:
>
> def delete_button(item_to_delete)
>     button_to t(''buttons.delete''), :action =>
"destroy", :controller
> => item_to_delete.class.to_s.downcase.pluralize
> end
>
> Normally i work with paths a la post_path(item_to_destroy) but I cant
> find a way of making that work for different models except throwing in
> some stupid switch statement which makes the code REALLY ugly..
>
> So the code above throws a route not found error. BUT:
> def delete_button(item_to_delete)
>     button_to t(''buttons.delete''), :action =>
"new", :controller =>
> item_to_delete.class.to_s.downcase.pluralize
> end
>
> works just fine.. these are the things that really annoy me about ruby
> on rails.
>
You''re not setting the method. REST dictates that the destroy action
can only be accessed by the DELETE method. Also, given that the path
you want to access is just the one for the post/comment/etc you don''t
need the path helper at all.

button_to ''Delete'', item_to_delete, :method =>
''DELETE''

should do the trick

Fred
> Also.. the most ridiculous thing happens at the moment.. I use the
> asset pipeline and after rebooting all javascript code in my file
> users.js.coffee doesnt get executed in my browser anymore.. If i put
> it in example ''messages.js.coffee'' it works just fine.
EXACTLY the
> same syntax in both files.. I have NO idea why that happens. But
> frankly after wasting 1h on that I dont care. Just leave my code in
> the wrong file where it works..