-2

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?

  • It seems as though the path you are trying to go to is not a valid path in your application, Could you please try running `rake routes | grep link` in your terminal and paste the result here? That would tell us more about the routes in your application. (Or you could paste relevant parts of `config/routes.rb` as well) – Anuj Khandelwal Oct 13 '19 at 14:24
  • see below - I have changed the string name to stop any confusions. All paths are valid. This is an upgrade to a working application. – Quentin Bushkas Oct 13 '19 at 14:30
  • `new_buyer_path` is a named route, it's not a string, `link_path` is just a variable storing a string, it just does not work that way, it's just a plain string. Maybe you can work with the URI module to handle the string as an actual URI https://ruby-doc.org/stdlib-2.6.5/libdoc/uri/rdoc/URI.html – arieljuod Oct 13 '19 at 14:33

3 Answers3

0

I'm not sure but You can list your available paths of your Rails app like:

bundle exec rails routes | grep link

to check that link_path is ready to use or not.

Dac Nguyen
  • 23
  • 1
  • 7
  • Thanks Dac, but link_path is actually a string called raw_cml. i'll edit the question so it is more clear - see its confusing now!! – Quentin Bushkas Oct 13 '19 at 14:29
0

Try to concat the parameters with the string url:

<% fixed_raw_cml = raw_cml + (raw_cml.include?('?') ? '&' : '?') %>
<%= link_to "Move", fixed_raw_cml + { score: '9', question:'8' }.to_query, class: "btn btn-pink" %>
demir
  • 4,591
  • 2
  • 22
  • 30
0

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