Use View Helper Methods in Controller (Rails 3)
http://wowkhmer.com/2011/09/09/use-view-helper-methods-in-rails-3-controller/
Use view_context
to get access to all helpers:
# app/controllers/posts_controller.rb
class PostsController < ActionController::Base
def show
# ...
tags = view_context.generate_tags(@post)
email_link = view_context.mail_to(@user.email)
# ...
end
end
# app/helpers/posts_helper.rb
module PostsHelper
def generate_tags(post)
"Generate Tags"
end
end
Written by Gilbert
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Related Tags
#rails
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#