How to dynamically call routes helper in rails?

前端 未结 2 1402
盖世英雄少女心
盖世英雄少女心 2021-02-03 21:08

For example, I have constructed a string called \"new_work_path\", now I want to call that helper as a method.

I\'ve tried send(\"new_work_path\", vars) and

2条回答
  •  囚心锁ツ
    2021-02-03 21:37

    My bad, as per @tadman suggested, I tried to use send(:new_work_path, args) again and it worked! Must have mistyped it before.

    Before finding out that send works right away, I had found another solution which is also of interest:

    new_polymorphic_path(Work, args)
    

    Which seems to offer some syntactic sugar as well.

提交回复
热议问题