Association information not being displayed in Rails 4? -
the current_user has 1 quiz has questions 1 through 5, entered here:
<%= form_for @quiz |f| %> <div class="field"> <!-- question 1 name --> <%= f.label :q1, "what first question?", :class => "edit_labels", :maxlength => 10 %> <%= f.text_field :q1, :placeholder => "question 1", :style => "text-align: center" %> </div> ,,,,
created in controller takes place
def landing @quiz = quiz.new end
in quizzes controller:
def edit @quiz = quiz.find(params:[id]) end def create @quiz = current_user.build_quiz(quiz_params) if @quiz.save flash[:success] = "updated" redirect_to '/' else render 'new' end end def quiz_params params.require(:quiz).permit(:q1, :q2, :q3, :q4, :q5) end def show @quizzes = quiz.all end
now, when try display users:
/users/index.html.erb <%= render @users %>
and in partial:
/users/_user.html.erb <%= user.username %> <%= user.quiz.q1 %> etc...more fields
it works producing usernames, not quiz.q1 specifically, get
undefined method `q1' nil:nilclass
but if type
<%= current_user.quiz.q1 %>
in 'welcome/landing.html.erb', produces correct result.
i appreciate much. thank you.
Comments
Post a Comment