You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the Contests controller example, I'm going to add a simple correction for the controller, because it throws an undefined method 'base_class'. I've solved it by adding this:
class ContestsController < ApplicationController
helper_method :survey, :participant
# create a new attempt to this survey
def new
@participant = current_user #notice this and the base_class error disappears
@attempt = survey.attempts.new
# build a number of possible answers equal to the number of options
survey.questions.size.times { @attempt.answers.build }
end
# create a new attempt in this survey
# an attempt needs to have a participant assigned
def create
@attempt = survey.attempts.new(params[:attempt])
# ensure that current user is assigned with this attempt
@attempt.participant = participant
if @attempt.valid? and @attempt.save
redirect_to contests_path
else
render :action => :new
end
end
def participant
@participant ||= current_user
end
def survey
@survey ||= Survey::Survey.active.first
end
end
But as I said before the 'base_class' error disappears and throws another error in the form.
<%= form_for [:contests, @attempt] do |f| %> <!-- the error is this line it says 'undefined method for contest_survey_attemps_path' -->
<%= f.fields_for :answers do |builder| %>
<ul>
<% @survey.questions.each do |question| %>
<li>
<p><%= question.text %></p>
<%= builder.hidden_field :question_id, :value => question.id %>
<% question.options.each do |option| %>
<%= builder.check_box :option_id, {}, option.id, nil %>
<%= option.text %> <br/ >
<% end -%>
</li>
<% end -%>
</ul>
<% end -%>
<%= f.submit "Submit" %>
<% end -%>
I'm using Rails 4
The text was updated successfully, but these errors were encountered:
Using the Contests controller example, I'm going to add a simple correction for the controller, because it throws an undefined method 'base_class'. I've solved it by adding this:
But as I said before the 'base_class' error disappears and throws another error in the form.
I'm using Rails 4
The text was updated successfully, but these errors were encountered: