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.