Question

The index path of quotes is stored and retrieved from var JobshopRfqx.quote_index_path. Here is how the variable is defined:

JobshopRfqx.quote_index_path = 'jobshop_quotex.quotes_path(:rfq_id => r.id)'

Here is the link_to which works (eval):

<%= link_to t('Quotes'), eval(JobshopRfqx.quote_index_path.to_s) %>

Here is the link_to which did not work:

<%= link_to t('Quotes'), Rails.application.routes.url_helpers.send(JobshopRfqx.quote_index_path.to_s) %>

Here is the error:

 ActionView::Template::Error:
       undefined method `jobshop_quotex.quotes_path(:rfq_id => r.id)' for #<Module:0x42d5c90>

Without eval, what's the right way to call a string path?

Was it helpful?

Solution

If you want to use send you have to pass the name of the method separately from the arguments. You'd have to do something like this:

Rails.application.routes.url_helpers.send('jobshop_quotex.quotes_path', :rfq_id => r.id)

But, I don't think that's going to do what you want though. I really don't understand why you'd want to do this...

OTHER TIPS

I don't know why you're doing this, but the correct thing to do here is to use a Proc.

JobshopRfqx.quote_index_path = Proc.new { |js_quotex, r| js_quotex.quotes_path(:rfq_id => r.id) }

Then you can get the path you are looking for by calling:

link_to t('Quotes'), JobshopRfqx.quote_index_path.call(jobshop_quotex, r)

I'm like 90% sure that you're designing your system poorly if doing the above is required. Without seeing the whole thing I can't give you any better suggestions.

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