Question

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)

Was it helpful?

Solution

Use polymorphic_path([:remove_country, :admin, @species], {country_id: country.id}).

OTHER TIPS

Ok, I made a hacky solution but I don't like it one bit:

<%= link_to "Remove", url_for([:remove_country, :admin, @species]) + "?country_id=#{country.id}", method: :delete %>

It's very ugly, please someone put me out of my misery and show me a nice way to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top