Answer the question
In order to leave comments, you need to log in
Ajax in rails. How to do view more?
Hi all. How to do get else in rails using ajax?
there is a link
<%= link_to main_index_path(:countNews => @news.count + 9), remote: true do %>
Больше новостей
<% end %>
Answer the question
In order to leave comments, you need to log in
The request goes to the controller. It needs to be processed.
In order for all these remote: true to work correctly, a library must be connected, for example, with jquery -
//=require jquery
//=require jquery_ujs
Then the magical behavior of all these attributes will appear.
After that, the request goes to the same controller as usual, but with the js format
In the simplest case, you just need to add a view, in your case:
And write a javascript code in it that will implement "show more". For example, insert (append) received variables (new news from the controller).
If the logic for html and js formats is different, then write in the action
# news_controllerb.rb
def index
#common format code
@news = News.all
respond_to do |format|
format.html{ #html specific code }
format.js{ #js specific code }
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question