using url_for in a lib folder module

后端 未结 2 1429
你的背包
你的背包 2021-02-13 02:58

I have a model with a field called \"type\" and a field called \"value\". The type field will determine how the \"value\" is parsed before rendering. I want this to be easily ex

相关标签:
2条回答
  • 2021-02-13 03:06

    Victory!

    include ActionView::Helpers
    include ActionDispatch::Routing
    include Rails.application.routes.url_helpers
    

    via http://apidock.com/rails/ActionController/UrlWriter

    0 讨论(0)
  • 2021-02-13 03:17

    An alternative to url_for you can use Rails.application.routes.url_helpers just add in route :as like the following example:

    get "sessions/destroy/:param_id", as: :logout 
    

    so you can use it as following:

    Rails.application.routes.url_helpers.logout_path(:param_id => your_value)
    

    This will do the same as url_for

    Hopefully, this would help

    0 讨论(0)
提交回复
热议问题