Last active
August 14, 2018 01:45
-
-
Save bmax/8760875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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