I am trying to implement a link in rails that will point to a certain url with a delete: method and with some params in the url, what I am trying is this:
<%= link_to "Remove", [:remove_country, :admin, @species, my_param: country.id ], method: :delete %>
Note the my_param: country.id I am trying to pass in. This gives me the result:
undefined method `model_name' for Hash:Class
due to the hash in the params. Unfortunately I need that there as I am trying to pass an extra param into the url (my_param which is country.id in this example)
as far as I can remember this is the correct method to pass params into a link_to in rails. The normal link_to that I use (without the my_param) is below, that works perfectly:
<%= link_to "Remove from this species", url_for([:remove_country, :admin, @species]), method: :delete %>
So how do I incorporate my param into this url? thanks in advance. (here is a source for why I think this should work)
Use
polymorphic_path([:remove_country, :admin, @species], {country_id: country.id})
.Ok, I made a hacky solution but I don't like it one bit:
It's very ugly, please someone put me out of my misery and show me a nice way to do this.