0

I'm developing a Rails plugin which needs to output a checkbox via a helper. The checkbox appears when placing the helper startup_exchange_optin('user') in a scaffolded Users#index view. Placing it in new, edit and show views I get NoMethodError:

undefined method `startup_exchange_optin' for #<User:0x0000010162c620>

File called by init.rb:

# lib/startup_exchange.rb
require 'startup_exchange/startup_exchange_helper'

module StartupExchange
end

ActiveSupport.on_load(:action_view) do
 include StartupExchange::StartupExchangeHelper
end

The helper:

# lib/startup_exchange/startup_exchange_helper.rb
module StartupExchange
  module StartupExchangeHelper
    def startup_exchange_optin(object_name, method = 'startup_exchange_optin', options = {}, checked_value = '1', unchecked_value = '0') 
      check_box(object_name, 'startup_exchange_optin', options, checked_value, unchecked_value)
    end
  end
end

The plugin is not going to be a gem, which is why the need for init.rb. At first I attempted to use Railtie but I couldn't get it to initialize. ActiveSupport.on_load seems to work for at least the index view.

Community
  • 1
  • 1
sime
  • 61
  • 1
  • 7

1 Answers1

0
check_box(object_name, 'startup_exchange_optin'...

#=> undefined method `startup_exchange_optin' for #<User:0x0000010162c620>

Your User object doesn't respond to `startup_exchange_optin' method.

Valery Kvon
  • 4,438
  • 1
  • 20
  • 15
  • Although the index view was rendering a check_box with an unknown method, the other actions were not. Which confuses me. It's a little clearer to me now that I need a method or column in the User model (or something it `acts_as`) to before a check_box was to be rendered. I cannot simple produce an unattached check_box. – sime Jan 16 '13 at 02:22