ruby on rails - Using Paginate on Certain Users in Database -


i using kaminari paginate traverse through users , give them evaluation. however, users can evaluate users, not of them, confused on how go this. tried creating array of users want display, did not work correctly since new ruby. understand that

<% @users.each |user| %> 

is traversing through entire list, not sure how edit needs. example, have role attribute each user. users each role evaluate other users same role. have tried doing like

<% @users.each |user| if @user.role == 1 %> 

but know that exact code verbatum won't work way i'd like, that's example of want if it's possible. in summary, choose in paginated list. below code trying do. each user has form.

<h2>back of house evaluation</h2> <br> </br>  <% @users.each |user| %>  <h4> <%= user.name  %> </h4> <h3> have heart?</h3>   <%= form_for(user) |f| %> <% begin %>          <div class="form-group">         <%= f.label :hunger_for_wisdom %></label         <div class="col-xs-10">         <div class="form-inline">         <div class="form-group">              <%= f.radio_button :current_one, 1 %>              <%= f.label :_1 %>         </div>         <div class="form-group">              <%= f.radio_button :current_one, 2 %>              <%= f.label :_2 %>         </div>         <div class="form-group">              <%= f.radio_button :current_one, 3 %>              <%= f.label :_3 %>         </div>         <div class="form-group">              <%= f.radio_button :current_one, 4 %>              <%= f.label :_4 %>         </div>         <div class="form-group">              <%= f.radio_button :current_one, 5 %>              <%= f.label :_5 %>         </div>     </div> </div>       <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 %> 

thank in advance!!

one way accomplish using method reject! user list. replace:

<% @users.each |user| %> 

by:

<% @users.reject!{|u| u.role != 1}.each |user| %> 

but i'd prefer filter out unwanted users list in controller, not in view. in controller call like:

@users = user.where(:role => role_id).page(params[:page]) 

where role_id id of role (1 example), , params[:page] page number want load kaminari.

hope helps out.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -