1

So, I have a weird problem. I have a Helper method in rails 3.2.9 that keeps giving me a method not found error when trying to call another method within the same module. I've tested it in the rails console and everything works as expected. Here's my code:

Helper Module:

module SomeHelper
  def options_for(field, options={})    SomeHelper.send(field).merge options end

  def seller_f_name_options()           {placeholder: 'First Name'} end
  def seller_l_name_options()           {placeholder: 'Last Name'} end
  def seller_email_options()            {placeholder: 'Email'} end
end

Controller View

<%= f.text_field :seller_l_name, options_for(:seller_l_name_options, {placeholder: 'AltFNText'}) %>

Rails Error:

    NoMethodError in Landing_pages#index

Showing /var/www/application/app/views/landing_pages/_form_lp2.html.erb where line #24 raised:

undefined method `seller_l_name_options' for SomeHelper:Module
Extracted source (around line #24):

21:       </div>
22:       <div style="float:right; width:50%;">
23:         <%= f.label "Last Name", :style=>"margin-left: 8px;" %><br>
24:         <%= f.text_field :seller_l_name, options_for(:seller_l_name_options, {placeholder: 'None'}) %>
25:       </div>
26:     </div>
27: 
Trace of template inclusion: app/views/landing_pages/template2.html.erb

Rails.root: /var/www/application

Application Trace | Framework Trace | Full Trace
app/helpers/some_helper.rb:2:in `options_for'
app/views/landing_pages/_form_lp2.html.erb:24:in `block in _app_views_landing_pages__form_lp__html_erb__4594666433786154550_70236178320020'
app/views/landing_pages/_form_lp2.html.erb:8:in `_app_views_landing_pages__form_lp__html_erb__4594666433786154550_70236178320020'
app/views/landing_pages/template2.html.erb:69:in `_app_views_landing_pages_template__html_erb__187408593000100027_35017480'
app/controllers/landing_pages_controller.rb:29:in `index'
config/initializers/quiet_assets.rb:7:in `call_with_quiet_assets'

Any help on this issue would be greatly appreciated!

1 Answers1

1

There's no need to call it through module, I mean SomeHelper.send(field). All these methods are somewhat instance methods, so it is enough to use just send(field).

This problem is more elaborated here.

Community
  • 1
  • 1
blelump
  • 3,233
  • 1
  • 16
  • 20
  • I noticed that self.send(field) works as well; which is more aligned with what I want to accomplish. This way it will only accept methods with its own module. – Christopher Brandt Nov 13 '14 at 18:16