문제

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?

도움이 되었습니까?

해결책

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...

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top