-
-
Save ashishwadekar/febe4e7454a0241a90f3ff7b24608d39 to your computer and use it in GitHub Desktop.
Accessing Helper modules in rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Accessing Helper modules in rails | |
http://www.funonrails.com/2010/12/accessing-helper-modules-in-rails.html | |
1. Helper methods all the time for views | |
class ApplicationController < ActionController::Base | |
helper :all# include all helpers, all the time for views | |
end | |
2. Controller methods in views | |
class ApplicationController < ActionController::Base | |
helper_method :current_store | |
#now controller_method can be accessed in views | |
end | |
2. Helper methods in controller | |
class ApplicationController < ActionController::Base | |
include ActionView::Helpers::ApplicationHelper | |
end | |
3. Helper methods in model | |
class Student < ActiveRecord::Base | |
include ActionView::Helpers::ApplicationHelper | |
end | |
4. Helper methods in mailer | |
class Notifier < ActionMailer::Base | |
add_template_helper(ApplicationHelper) | |
#... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment