I am somewhat new to Rails, and I am learning off of a tutorial online. The guy in the videos talked about how you have to have an if statement to decide if the save worked or not.
This is my code:
def create
@quiz = Quiz.new(quiz_params)
if @quiz.save
flash[:notice] = "Your quiz has been created."
redirect_to action: 'index'
else
render('new')
end
end
The quiz_params was defined as such:
params.require(:quiz).permit(:title, :summary, :visible)
For some reason, it refuses to redirect to the index function, deciding to stay on the same page while the URL changes from localhost:3000/quizzes/new
to localhost:3000/quizzes
.
The guy who taught the tutorial had this code.
def create
@subject = Subject.new(subject_params)
if @subject.save
flash[:notice] = "Subject created succesfully."
redirect_to(subjects_path)
else
render('new')
end
end
The subject_params went as such:
params.require(:subject).permit(:name, :position, :visible)
Other than the wording in the quotes and the name of the model and variables, I am not sure what the difference is. I am being as consistent as I can, so there shouldn't be any difference.
Sorry if the formatting is bad.