How to define a Rails Helper for one specific action?

I have a LabelTagHelper with a custom method label_tag, but I need this method only in the new , create , edit and update .

Is there a way to define this helper only for a specific action? Something like helper :label_tag, :only => [:new, :create, :update, :destroy]? Or is it safe to call self.class.helper :label_tagin the before_filter file?

+3
source share
2 answers

Helpers rails should be just formatting. Think of it the same way as functions that decorate your presentation level (view)

: before_filter . .

, . , . , / .

, ,

Sameera

+1

,

, ( "ProjectsHelper" )

module ProjectsHelper
  def label_tag *params
    if controller.action_name == "index"
      #user custom implementation
    else
      super
    end

  end
end

... , , ,

Sameera

: . , ,

0

All Articles