I have an Schedule model where user selects hours and specific days of week (e.g 3hrs monday, tuesday, saturday). My migration looks like
class CreateSchedules < ActiveRecord::Migration
def change
create_table :schedules do |t|
t.integer :hourss
t.integer :user_id
t.boolean :monday
t.boolean :tuesday
t.boolean :wednesday
t.boolean :thursday
t.boolean :friday
t.boolean :saturday
t.boolean :sunday
t.timestamps
end
end
end
How do I write form in views to show checkbox for weekdays and one selects some, boolean value should be set to true. I am using Simple Form and Rails 3.2.7
With simple form its really easy. Just do
= f.input :monday
= f.input :tuesday
etc. Simple form auto converts boolean db items to checkboxes