How to capture binding value from url in Ruby on Rails?

After updating or creating an entry, I use the URL helper to redirect to the part on which the entry was found:

if record.save
  ....
  redirect_to records_url, :anchor => "record_" + record_id.to_s
end

the resulting URL will look like

http: // localhost: 3000 / records # record_343242

I want to highlight an entry using jquery or prototype, and binding is the exact identifier I'm looking for. Can i grab it?

+3
source share
1 answer

I assume you are trying to capture it in JavaScript?

var record_id = window.location.href.hash.split("_")[1];

In Prototype, you can write:

var record_id = window.location.href.hash.split("_").last;
+1
source

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


All Articles