Tom Lehman
Tom Lehman

Reputation: 89373

Use helper methods within a controller

I defined a helper abc() in annotations_helper.rb. What do I have to do such that I can use this method in annotations_controller.rb?

Upvotes: 0

Views: 161

Answers (2)

Waseem
Waseem

Reputation: 8402

This is usually not a good practice to use a helper in your controllers. You should try to move the logic inside a model or if the logic is too generic, you should move that to lib/some_lib.rb and include that in your model to use.

However check out this blog post if you really want to do this. Don't forget to read the comments.

Upvotes: 1

Mike Buckbee
Mike Buckbee

Reputation: 6993

In general helpers are supposed to be "view helpers" and not called from controllers.

You probably want to put something like that in application_controller.rb

Upvotes: 1

Related Questions