Always I am indebted.
As the title says, the model search results are narrowed down by the query parameter conditions on the controller side, and the model is passed to the view side and displayed.
The display uses kaminari, which is a paging gem, and if you press "more", 5 items will be displayed at a time.
It's been messed up, but in the end @items is in ActiveRecord format, which is the data you actually want to display.
There are 30 lines in the entire model, and if you narrow down to 10 with the controller, it is assumed that 5 will be displayed in the first display and the remaining 5 will be displayed when you press "more". If i keep it as it is, when you press View more, you will get 5 records on the 2nd page from the total 30 data.
When I stopped with pry in javascript, only page = 2 information was passed to the query parameter when "more" was pressed.
It is an automatic raw link of kaminari ↓
<% = link_to_next_page @items,'more', remote: true, id:'more_link'%>
How can I pass parameters such as search to?
It doesn't matter if it is a reference site, so I would appreciate it if you could teach me the appropriate method.
Thank you.
environment
Amazon Linux release 2 (Karoo)
Rails 5.2.3
Ruby version: 2.6.1
# xxxx.controller.rb
def show
@items_tmp = []
if! params [: jouken1] .nil?
# Filtering process User.where (xxx: yyyy) etc.
end
if! params [: jouken2] .nil?
# Filtering process User.where (xxx: yyyy) etc.
end
・ ・
・ ・
・ ・
#Revert array to Activereecord
@items = @items_tmp .first.class.where (id: arr.map (&: id)) .page (params [: page]) .per (5) .order (created_at: "DESC")
render "xxxxx/show"
end
# show.html.erb
<% = render'items'%>
<% = link_to_next_page @items,'more', remote: true, id:'more_link'%>
# _items.html.erb
<% @ items.each do | item |%>
<% item.id%>
<% item.name%>
・
・ ・
・ ・
<% end%>
# show.js.erb
$('#items'). append ("<% = escape_javascript (render'items', object: @items)%>");
$("# more_link"). replaceWith ("<% = escape_javascript (link_to_next_page (@items,'more', remote: true, id:'more_link'))%>");
<% # binding.pry%>
-
Answer # 1
-
Answer # 2
For me
Get all 10
Hide the 6th and subsequent items with CSS on the view side
If you press "more" in CSS or JavaScript, the 6th and subsequent items will be displayed.
Do you want to implement it with■ Addition
You've already implemented Ajax for "more". I overlooked it.
In the current situation, even if you get it with Ajax, render has been executed, so only 5 new ones are displayed.
When using Ajax, it is necessary not to render.Try changing to execute the js file at the time of Ajax using format.js etc.
Related articles
- php - only the search result page is not displayed in alphabetical order
- ruby - i want to search the data of a nested model using ransack
- mysql - call model in viewhelper and pass the search result to view
- ruby - i want to search for form information in rails and save the result
- ruby - rails even if i create a new model (user), it is not displayed
- ruby - the view of the search screen is not displayed
- ruby - how to search by following the hash hierarchy
- ruby on rails - when i make a message, i want the date to be displayed, but i get "undefined method` strftime' for nil: nil
- ruby - pass the value from the controller in the rails model
- sql execution result cannot be received and displayed in ruby
- ruby on rails multiple keyword search i don't know how to write
- ruby - [rails/rspec] intermediate table model test does not pass
- ruby - [rails] i want to create a page where the url does not change by redirect even if i enter a value and search like a site
- ruby - i want to receive and search with multiple params
- ruby on rails - search for related models
- ruby - unable to create rails model (environment: cloud9)
- ruby - rails i want to search by multiple keywords
- error when implementing search function using ransack in ruby on rails
- ruby on rails - about the code of the adjacency list model implemented in rails
- in ruby on rails, i want to limit it to information other than foreign key constraint in references
- ruby - i want to solve the n + 1 problem when using rails where method in loop processing
- ruby - the image is displayed as strange characters in rails
- html - i would like to know how to calculate the average of the data
- ruby - i want to get it at intervals by searching using rails active record
- ruby - [rails] duplicate column name: it is displayed as reset_sent_at, but i do not know the duplicated part
- ruby - i don't feel that the sql issued by rails has a different format from the sql that i usually write
- ruby - passing variables using render partial
- ruby - [rails] [asynchronous] like function: the number of likes is not displayed normally
- ruby - about record duplication
It was solved by adding a parameter in the following form to the argument of the method "link_to_next_page" that creates more view in view.
show.html.erb
<% = link_to_next_page @items,'more', remote: true, id:'more_link', params: params.permit!%>