有人问,如何在Rails的控制器中取得URL中的锚点的值,这个需求比较奇特,以前没搞过,于是google了一把,在“Getting the # value
”
这个帖子看到有人有类似的问题,他说出了在controller中直接取不到的原因是“For normal links/urls the
#anchor is a client side feature and is often not even sent to the
server as part of a
request.”,恩,确实直接取不到,只能使用类似JS的方法来取了,因为其没有将URL全部提交到服务端,所以是无法取值的。
另外,看了下Rails中生成anchor的方法比较简单,如下:
Ruby代码
-
<%= url_for(
:action
=>
'play'
,
:anchor
=>
'player'
) %>
-
-
-
<%= url_for(:action
=>
'checkout'
,
:anchor
=>
'tax&ship'
) %>
-
-
-
<%= url_for(:action
=>
'checkout'
,
:anchor
=>
'tax&ship'
,
:escape
=>
false
) %>
-
详细的请参考API:
ActionView::Helpers::UrlHelper
分享到:
相关推荐
rails常用命令,例如新建rails项目,新建controller、model 等等
routing-filter 包裹了 Rails 路由系统的复杂野兽,在 Rails URL 识别和生成中提供了看不见的灵活性和强大功能 路由过滤器围绕着复杂的野兽,Rails 路由系统在 Rails URL 识别和生成中提供了看不见的灵活性和强大...
Rails :: Controller :: Testing 这个gem将assigns给控制器测试的内容... 如果您使用的是rspec-rails的旧版本,则可以在rails_helper手动添加模块。 RSpec . configure do | config | [ :controller , :view , :re
Ruby on Rails中文指南
rails-assets, 在 Rails 中,资产管理的解决 Rails 资产 Bundler 到 Bower 代理本自述文件涉及项目的开发方面。 访问站点了解如何在你的应用程序中使用 Rails 资产。 插件开发设置git clone git@github.com:tenex/r
Ruby On Rails中文教材(PDF)
使用Aptana+Rails开发Rails Web应用 有Aptana的安装配置等等,中文
rails指南 中文版
shoppe-example, 在 Rails 中使用Shoppe平台的示例存储实现 这是一个 Rails 应用程序,它使用 Shoppe 构建。 它具有一个可以爱的设计,以充分演示Shoppe平台提供的功能以及它在 Rails 应用程序中的。 正在启动要开始...
rails_email_preview, 在 Rails 中,预览和编辑应用程序邮件程序模板 Rails 电子邮件预览 使用这里 Rails 引擎在浏览器中预览电子邮件。 兼容 Rails 4.2 。电子邮件审阅: 所有电子邮件预览的列表: 代表有两个主题...
让你知道在rails中如何使用路由,路由与URL是如何对应的。
敏捷Rails中文教程 敏捷Rails中文教程 敏捷Rails中文教程
简介 Ruby On Rails 框架自它提出之日...Rails 是一个真正彻底的 MVC(Model-View-Controller) 框架,Rails 清楚地将你的模型的代码与你的控制器的应用逻辑从 View 代码中分离出来。Rails 开发人员很少或者可能从未遇到
在过去的几年中,《Ruby on Rails Tutorial》这本书被视为介绍使用 Rails 进行 Web 开发的先驱者。 在这个全球互联的世界中,计算机编程和 Web 应用程序开发都在迅猛发展,我很期待能为中国的开发者提供 Ruby on ...
Rather than toss you into the middle of the framework’s Model-View-Controller architecture, as many books do, Learning Rails 5 begins with the foundations of the Web you already know. You’ll learn ...
bower-rails, 在 Rails 上,为 Bower 设置类似 DSL + rake任务 rails Bower 对 Rails 项目的支持。 依赖文件是 Rails root 目录中的bower.json,如果使用 DSL,则为 Bowerfile 。 查看最新变更和发布的变更日志文件...
NULL 博文链接:https://hlee.iteye.com/blog/587000
Record Cache - 在Rails 3中缓存Active Model Records