Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture an anchor value from url in Ruby on Rails?

After updating or creating a record I use url helper to redirect to the part on the page where the record happened to be located:

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

the resulting url will be something like

http://localhost:3000/records#record_343242

I want to highlight the record using jquery or prototype, and the anchor is the exact id that I am looking for. Can I capture it?

like image 306
dimus Avatar asked Dec 08 '25 13:12

dimus


1 Answers

I presume you're trying to capture it in JavaScript?

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

In Prototype you could write:

var record_id = window.location.href.hash.split("_").last;
like image 112
Dave Nolan Avatar answered Dec 11 '25 02:12

Dave Nolan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!