在没有默认值的情况下获取 rails 'params'? [英] Getting the rails 'params' without the defaults?

查看:41
本文介绍了在没有默认值的情况下获取 rails 'params'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rails 中是否有一种巧妙的方法来获取参数的哈希值,而无需使用默认的动作"和控制器"?基本上没有任何不是我添加的参数.

Is there a neat way in rails to get a hash of the params without the default ones of 'action' and 'controller'? Essentially without any param that wasn't added by me.

我已经解决了:

parm = params.clone
parm.delete('action')
parm.delete('controller');

但是想知道是否有更简洁的方法来做到这一点?

But wondering if there is a neater way to do this?

推荐答案

你可以使用 except:

You could use except:

params.except(:action, :controller)

http://as.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Except.html

这篇关于在没有默认值的情况下获取 rails 'params'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆