Skip to content

Instantly share code, notes, and snippets.

@bmax
Last active August 14, 2018 01:45
Show Gist options
  • Save bmax/8760875 to your computer and use it in GitHub Desktop.
Save bmax/8760875 to your computer and use it in GitHub Desktop.
question controller
31 def create
32 params[:question][:subjects].delete_if { |n| n == "" }
33 Question.create(question_params);
34 # Question.create(:title => params[:question][:title],
35 # :summary => params[:question][:summary],
36 # :subject_id => params[:question][:subject])
37 end
38
39 def question_params
40 params.require(:question).permit(:title,:summary,:subjects)
41 end
question model
1 class Question < ActiveRecord::Base
2 belongs_to :user
3 has_many :QuestionSubjects
4 has_many :subjects, :through => :QuestionSubjects
5 has_many :answers
6 end
Subject model
class Subject < ActiveRecord::Base
2 has_many :QuestionSubjects
3 has_many :questions, :through => :QuestionsSubject
4 end
QuestionSubject Model
class QuestionSubject < ActiveRecord::Base
2 belongs_to :question
3 belongs_to :subject
4 end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment