Custom on page with stoner

I use Kaminari stone with rails 3.2. It is working correctly. Now I want to add a custom page to the page with the parameters [5, 10, 15, 20]. On each page, the selected page links must retain the value of each page. What is the best approach to implement these custom functions on the page?

+6
source share
2 answers

Add a GET form.

<%= form_tag posts_path, method: :get do %> <%= select_tag :limit, options_for_select([5, 10, 15, 20], selected: params[:limit] || 10) %> <% end %> 

And in your controller add

 @posts = @posts.per(params[:limit]) if params[:limit] 

This assumes that your resource is messages, but obviously you can change it to everything you do on the page.

Of course, you need to somehow invoke the form by adding a submit button or via javascript.

+7
source

There is a better guide that simply explains how the Kamari stone works, I suggest you just read this tutorial. http://railscasts.com/episodes/254-pagination-with-kaminari . Kamirari-gemstone is the best that helps split the page.

 @products = Product.order("name").page(params[:page]).per(5) 

for your custom option, you should read your option from the drop-down list and replace the variable 5 that we received from the user. for popup

 <td><%= f.select :experiance_year, options_for_select([*0..10 ],0)%></td> 

here experiance_year is a variable that receives input from the user.

+1
source

Source: https://habr.com/ru/post/944511/


All Articles