I'm trying to access a helper variable from a haml view in my project. I have the helper defined in rails-root/app/helpers/table_field_helper.rb:
module TableFieldHelper
def table_display_fields
MORE_COMPLICATED_TABLE_DISPLAY_FIELDS #some array defined elsewhere in the file
end
...
end
And trying to iterate over table_display_fields in index.html.haml:
...
%tr
%th
- table_display_fields.each do |field|
%th= field
...
I'm getting an error: undefined local variable or method 'table_display_fields'
What's causing this error? Why am I unable to access the definition in TableFieldHelper? I am new to Ruby/Rails, but I was under the assumption that all helpers are implicitly included in view/layout files, and nothing I've read would suggest I have to do anything extra to make them work together. Thanks!
If the helper class name is not the same as the controller name then you will have to manually require the helper class. http://api.rubyonrails.org/classes/ActionController/Helpers.html You can either change the name of the helper class to the same name as the controller that you are using it in, or you can include it in the controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With