如何从Ruby on Rails中的url中捕获锚点值?

时间:2022-11-27 17:55:58

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:

更新或创建记录后,我使用url helper重定向到记录恰好位于的页面上的部分:

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

the resulting url will be something like

生成的URL将是类似的东西

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?

我想使用jquery或prototype来突出显示记录,而锚点是我正在寻找的确切ID。我可以抓住它吗?

1 个解决方案

#1


1  

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

我认为你试图用JavaScript捕获它?

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

In Prototype you could write:

在Prototype中你可以写:

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

#1


1  

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

我认为你试图用JavaScript捕获它?

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

In Prototype you could write:

在Prototype中你可以写:

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