0

I need to have always up to date params[:id] which I want to use in view, to sort articles from DB.

How can I Refresh my URL params without refreshing the whole page on Rails?
Here is my code:

home.html.erb

...
<div id="bottom_menu">
  <h1>Продукты</h1>
  <div class="bottom_punct">
    <% @articles.each do |article| %>
      <div class="bottom_punct">
        <h2><%= params[:id] %></h2>
        <img src=<%= article.img %>>
        <a><br><%= article.description %></a>
      </div>
    <% end %>
  </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript" ></script>
<script src="/js/main.js.erb"></script>

main_controller.rb

class MainController < ApplicationController
  def home
    @articles = Article.all
    @id = params[:id]
  end
  def service
  end
  def questions
  end
  def contact
  end
  def partners
  end
end

URL params sets in js file by this code

$( ".npn, #Perf" ).click(function() {
   setLocation("?id=" + this.id);
});
SherylHohman
  • 16,580
  • 17
  • 88
  • 94
  • 1
    You mean the [HTML5 History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API)? – tadman Aug 12 '17 at 21:14
  • 3
    There isn't really a question here, can you be more specific about what you're asking please? – michaeldever Aug 12 '17 at 21:56
  • Marked as a dupe - this is really just a general browser question and has very little to do with rails. – max Aug 13 '17 at 05:00

0 Answers0