Order of including Helpers in ViewControllers

90 Views Asked by At

In rails app, how are helpers included in viewcontrollers, and what's the order of includion(which helper is included first, second, so on)?

Also, are all helpers available to views? If so, does the inclusion order same as the view's corresponding controller?

1

There are 1 best solutions below

2
On BEST ANSWER

Any controller can have a corresponding helper.

For example if you have a controller named Question (questions_controller.rb), it can have a helper named questions_helper.rb. The question helper is accesible only to the views corresponding to the question controller.

Besides you will have an Application helper (application_helper.rb) which is accessible to all the views in the application.

All helpers are not available to views by default. But you can include other helpers in a helper like this:

module MyHelper
  include QuestionsHelper
end

You can also use a helper inside a controller like:

class MyController < ApplicationController
  include MyHelper

  def my_method
    ...
  end
end