0

I am creating an evaluation form where a user will submit form after form by using kaminari pagination. The way I have it set up right now though is that the user will answer the questions, submit the form with an f.submit button, then once the profile updates, the user will have to manually select 'Next User' using the paginate button below the f.submit button. I would love for it to both submit the form and send the user to the next evaluation in line under one button action, not two. I have been playing around with trying to incorporate the paginate code into my f.submit button, but it keeps throwing errors. I was wondering if there was an easy way to go about this, thanks in advance!

<h2>Team Member Evaluation</h2>
<br> </br>

<% @users.each do |user| %>

    <h4> <%= user.name %> </h4>

    <%= form_for(user) do |f| %>
    <% begin %>

    <h8> Hunger for Wisdom </h8>
        <div class="form-inline">
        <div class="form-group">
             <%= f.radio_button :current_one, 1 %>
             <h7> 1 </h7>
        </div>
        <div class="form-group">
             <%= f.radio_button :current_one, 2 %>
             <h7> 2 </h7>
        </div>
    <% end %>

     <div class="col-md-3 col-md-offset-4">
     <%= f.submit "Submit Score", class: "btn btn-default" %>

    <% rescue ActionController::RedirectBackError %>

    </div>
    </div>

<% end %>
<%= paginate @users %>
<% end %>
<% end %>

Right now it is set up to whenever the user submits the form, the rescue action will direct the user back to a refreshed page of the evaulation form they just submitted, and then they must click next where the <% paginate @users %> is to go to the next form. I would like once the f.submit button is pressed to update and then immediately take the user to the next form.

user3376654
  • 67
  • 1
  • 9

1 Answers1

0

In the controller action for the submit you could just increment the page count like this:

@users = User.page params[:page].to_i + 1

This is assuming you aren't using any other scopes to get the @users collection. The kaminari github repo has more information on available methods here.

If it is on the first page then the page query var is probably nil so you would have to account for this and send it to page 2 in this special case.

trueinViso
  • 1,354
  • 3
  • 18
  • 30