I'm learning ROR and working on a voting style application, I've got my four tables up and running Users, Questions, Options and Answers and I can write to the Answers table via MySQL and the total votes are displaying so far which is great.
I'm having a problem with getting a +1 button working (eventually it'll be unique per user but for now I just want to see it working).
I'm fairly certain my files are all setup correctly but I'm confused with what to put in my Questions "Show" view for the button, it might be a routes problem as it does say
undefined method 'upvote_option_path'
<% @question.options.each_with_index do |option, index| %>
<p><%= option.option_text %></p>
<p><%= pluralize(option.answers.count, "vote") %><br><br></p>
<p><%= button_to '+1', upvote_option_path(option), method: :post %></p>
<% end %>
@question = Question.find(params[:question_id])
@option = Option.find(params[:option_id])
Answer.create(user_id: current_user.id, question_id: @question, option_id: @option)
resources :questions do
resources :options do
question_option_upvote POST /questions/:question_id/options/:option_id/upvote(.:format) options#upvote
undefined method upvote_option_path
According to your routes, there is no
upvote_option_path, it should be
question_option_upvote_path. Also the path takes two arguments as keys(
:option_id), so you need to pass those two to the path.
The below should work
<%= button_to '+1', question_option_upvote_path(@question, option), method: :post %></p>