Search code examples
ruby-on-railsurlparameterslink-to

adding params to a path defined by a string - rails


I have the following link that passes parameters to the url, and it works fine.

<%= link_to "Buy", new_buyer_path(plan: 'item_D78387628dd', cost:'$45.00'), class: "btn btn-pink", role: "button" %>

However, I have a second link that takes its path from a string called raw_cml - raw_cml works fine without the params added.

as an example

raw_cml = dashboards/imp/budget_mgmt

<%= link_to "Move", raw_cml(score: '9', question:'8'), class: "btn btn-pink" %>

In this example i get the following error:

undefined method `raw_cml'

Can someone help me move in the right direction?


Solution

  • I did a bit more research into this and found that .to_params gave a one line approach.

    <%= link_to "Improve", raw_cml + '?' + { uqr: qid }.to_param, class: "btn btn-pink" %>
    

    Seems to be giving the same results.

    I'd be interested in any unforeseen consequences of this method?

    Thanks