dimus
dimus

Reputation: 9372

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?

Upvotes: 3

Views: 2738

Answers (1)

Dave Nolan
Dave Nolan

Reputation: 3009

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;

Upvotes: 1

Related Questions