add checkbox with simple_form without association with model?

Mikhail Grishko picture Mikhail Grishko · Feb 7, 2012 · Viewed 42.3k times · Source

How I can add checkbox with simple_form without association with model? I want to create checkbox which will handle some javascript events, but don't know? Maybe I miss something in documentation? Want't to use similar like following:

= simple_form_for(resource, as: resource_name, url: session_url(resource_name), wrapper: :inline) do |f|
  .inputs
    = f.input :email, required: false, autofocus: true
    = f.input :password, required: false
    = f.input :remember_me, as: :boolean if devise_mapping.rememberable?
    = my_checkbox, 'some text'

Answer

Gacha picture Gacha · Feb 7, 2012

You can add a custom attribute to the model:

class Resource < ActiveRecord::Base
  attr_accessor :custom_field
end

Then use this field as block:

= f.input :custom_field, :label => false do 
  = check_box_tag :some_name

Try to find "Wrapping Rails Form Helpers" in their documentation https://github.com/plataformatec/simple_form