I've got a HAML partial that receives a variable bar
, and I'd like to inject that variable in the link_to path.
For example:
= link_to new_foo_path, class: 'source card' do
.stuff
I want to replace foo with bar.
I've tried:
= link_to new_#{bar}_path, class: 'source card' do
and a dozen other things, but nothing seems to work.
Thoughts?
You can try it like this:
link_to send("new_#{bar}_path"), class: "source card" do
Basically, send makes something a method or variable, and it allows you to combine everything in that string into one variable.
You can add parameters to the link helper like this:
link_to "New Foo", new_foo_path(bar: "bar")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With