/ ruby

Calling View helper methods from Controller / Model in Rails

Recently I was researching a way to use link_to inside my Rails 3 controller, and learned about the method view_context.

So if you ever want to access view helper methods from controller / models in rails 3 you have to use view_context method.


view_context.link_to 'Link', link_path(@link)}.


Just a note that you should avoid calling these functions within the controllers to follow mvc pattern conventions.

Manu S Ajith

Manu S Ajith

Tech Entrepreneur, dating Elixir, in long-term ❤️ w/ Ruby, had multiple one night stands w/ Go. Into functional paradigms DDD/CQRS/EventSourcing architecture these days. @manusajith on the interwebs

Read More