(GoRails)链接link_to到当前页current Page 并使用参数 (类ActionController::Parameters)
https://gorails.com/episodes/rails-link-to-current-page-with-params?autoplay=1
如何链接到当前页并增加,移除,或者修改URL中的params。
当使用search or index pages with filters很方便。
<%= link_to "Customers", root_path %> <%= link_to "Paid Customers", root_path(paid: true) %>
#对URL中的参数进行筛选
<%= link_to "Customers Date Range", request.params.except(:end) %> <%= link_to "Paid Customers Date Range", current_page_params.merge(paid: true) %>
假如:http://localhost:3000/?start=1990&end=2020
通过except方法,最后只会得到 Parameters: { "start" => 1990 }
merge方法,是把paid参数加入到URL中。
这些方法都是ActionController::Parameters类中的方法
把request.params定义成一个helper方法:
#app/helpers/xxx_helper.rb
module HomeHelper
def current_page_params
request.params.slice("paid", "query", "filter", "sort")
end
end #slice是参数白名单
(GoRails)链接link_to到当前页current Page 并使用参数 (类ActionController::Parameters)的更多相关文章
- 小程序报错Do not have xx handler in current page的解决方法
看到小程序这一大串的“Do not have bindName handler in current page: pages/card/card. Please make sure that bind ...
- [HTML5] Add Semantic Styling to the Current Page of a Navigation Item with aria-current
In this lesson, we are going to use aria-current to give a screen reader user more context about wha ...
- EBS 开发中如何动态启用和禁止请求(Current Request)的参数
EBS 开发中如何动态启用和禁止请求(Current Request)的参数 (版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 我们可以使用依赖 ...
- Do not have XXX handler in current page
这种错误没有什么技术含量,也很容易解决. 一般就是wxml里面的button/form之类的,你用bindtap/bindsubmit给它绑了一个XXX函数,但是呢,你没有在相关js页面里面定义这个函 ...
- 从链接上获取参数值, location.href上获取参数
/** * 用页面链接上获取参数 * @param {String} name 要获取的参数名 * @return {String} 参数值 */ base.getQueryStringRegExp ...
- System.Web.UI.Page的页面基类
服务器端的page类 所有我们编写的页面都继承自page类,可见page类是非常重要的,page类提供了哪些功能,直接决定了我们的页面类可以继承什么功能,或者说,直接决定了我们的页面类功能的强大与否! ...
- JDBC中链接数据库前为什么要用Class.forName(驱动类)加载驱动类?
使用JDBC链接数据库时,为什么要先使用Class.forName(String name)来加载类? 答: 实际上就是为了加载类时,调用静态初始化块中的注册函数. 可以看一下MySql的Driber ...
- easyui loader 改变rows total page rows等参数名称!
公司需要对接客户接口,但客户接口已经确定,分页请求的参数以及返回的数据是客户自定义的名称,与easyui 所封装的参数无法对应,这是需要改变参数名称,这时我们可以使用loader方法: loader: ...
- 继承System.Web.UI.Page的页面基类
服务器端的page类 所有我们编写的页面都继承自page类,可见page类是非常重要的,page类提供了哪些功能,直接决定了我们的页面类可以继承什么功能,或者说,直接决定了我们的页面类功能的 ...
随机推荐
- ol3对地图上某些特定的经纬度进行标注
最终效果需要类似于这种 1.首先我们需要一个最基本的地图,这一步骤可以浏览该分类下的上一篇随笔. 2.ol3支持的文件格式有.geojson,我们需要将坐标制作成符合这种格式的样子才能被ol3识别并显 ...
- 使用svn导入项目
打开eclipse工作平台点击“File”-->import如下图: 在项目导入框中找到SVN选择“从SVN检出项目”然后点击“下一步”,出现如下界面: 在上图界面中选择“创建新的资源库 ...
- Junit的套件使用
定义一个类,在类的上方添加@RunWith(Suite.class)和@SuiteClasses({XX.class,YY.class,...}) 实例有两个类分别为:public class Log ...
- topcoder srm 315 div1
problem1 link 直接模拟即可. import java.util.*; import java.math.*; import static java.lang.Math.*; publi ...
- 探究is与==的区别
1.is 和 ==的区别: 主要参考内存地址: 部分字符串和数字有固定的小数据池: 比如: a="abc" a1="abc" print(id(a),id(a ...
- Bootstrap3基础 glyphicon 设置图标的颜色与大小
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- Flask学习【第4篇】:用Flask的扩展实现的简单的页面登录
from flask import Flask,render_template,request,redirect,session app = Flask(__name__,template_folde ...
- 图片处理工具类 util
PathUtil package util; public class PathUtil { private static String seperator = System.getProperty( ...
- (zhuan) Speech and Natural Language Processing
Speech and Natural Language Processing obtain from this link: https://github.com/edobashira/speech-l ...
- Nand flash code
(1)流水灯 1>我们来看原理图 2>datasheet 3> ...