Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3. How to add a helper that ActiveAdmin will use?

I'm creating a helper to be used by Formtastic but I get the undefined local variable or method error. I don't know where to put it so it can work.

I already tried in the application_helper.rb and in app/helpers/active_admin/view_helpers.rb

like image 252
leonel Avatar asked Dec 29 '11 20:12

leonel


People also ask

How do you use the helper method in Ruby on Rails?

A Helper method is used to perform a particular repetitive task common across multiple classes. This keeps us from repeating the same piece of code in different classes again and again. And then in the view code, you call the helper method and pass it to the user as an argument.

Can we use helper method in controller Rails?

In Rails 5, by using the new instance level helpers method in the controller, we can access helper methods in controllers.


1 Answers

You can define them in app/helpers/ as you tried but you need to include them trough the active admin's initializer like this:

# in config/initializers/active_admin.rb ActiveAdmin.setup do |config|     .... end  module ActiveAdmin::ViewHelpers   include ApplicationHelper end 
like image 102
Bishma Stornelli Avatar answered Oct 05 '22 22:10

Bishma Stornelli