How can I use image_path inside Rails 3 Controller

前端 未结 1 1628
挽巷
挽巷 2020-12-24 13:23

An identical question has been asked before AssetTagHelper::image_path outside views but the solution does not work for Rails 3.

I have a requirement where I am r

1条回答
  •  失恋的感觉
    2020-12-24 13:27

    You can use view_context in your controller when doing 'view' tasks like generating links. The good thing about it is you don't have to include the view helpers in your controller.

    e.g. in your controller you can create a variable which will be a html link with link_to or url_for if you just want the link, 'only_path' option set to false should give you absolute url.

    link = view_context.url_for(:action => 'login', :controller => 'members', :only_path => false)
    

    Hope this helps.

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