Rails view helpers in controller.
I recently ran into a problem where I wanted a flash message to contain a link. But the link_to
method isn't accessible from the controller.
How do you get around it? You can access your view using view_context.
app/controllers/sessions_controller.rb
flash[:alert] = "#{view_context.link_to 'Forgot your password?', forgot_password_path}"
Link:
http://apidock.com/rails/AbstractController/Rendering/view_context
Written by Tal Safran
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#