Skip to content

Instantly share code, notes, and snippets.

@addame
Forked from Amitesh/rails_helper.rb
Created April 28, 2012 21:07
Show Gist options
  • Save addame/2522003 to your computer and use it in GitHub Desktop.
Save addame/2522003 to your computer and use it in GitHub Desktop.

Revisions

  1. @Amitesh Amitesh revised this gist Apr 28, 2012. No changes.
  2. @Amitesh Amitesh created this gist Apr 28, 2012.
    49 changes: 49 additions & 0 deletions rails_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    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