Skip to content

Instantly share code, notes, and snippets.

@bmax
Created February 1, 2014 23:16
Show Gist options
  • Save bmax/8760522 to your computer and use it in GitHub Desktop.
Save bmax/8760522 to your computer and use it in GitHub Desktop.
controller
def create
32 params[:question][:subjects].delete_if { |n| n == "" }
33 Question.create(:title => params[:question][:title],
34 :summary => params[:question][:summary],
35 :subject_id => params[:question][:subjects])
36 end
model
1 class Question < ActiveRecord::Base
2 belongs_to :user
3 has_many :subjects
4 has_many :answers
5 end
view
<div><%= f.label :subjects %></div>
9
10 <div><%= f.collection_check_boxes(:subjects, Subject.all, :id, :name) %></ div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment