Categories
ruby on rails

Calling View helper methods from Controller / Model in Rails 3.* and Rails 2.*

To access view helper methods from controller / models in rails 3 you have to use view_context method. Example

view_context.link_to "This is my link", "/"

In rails 2 you have to user @template instance variable as shown below

@template.link_to "This is my link", "/"

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