简体   繁体   English

Rails Params哈希如何提供给控制器方法

[英]how is rails params hash made available to controller methods

I understand the rails params hash is available in my controller methods, but I'm trying to understand how that happens. 我知道我的控制器方法中提供了rails params哈希,但是我试图了解它是如何发生的。 Is it a parameter passed to the method? 它是传递给方法的参数吗? If so, how can we access it since controller methods don't have any declared arguments? 如果是这样,由于控制器方法没有任何声明的参数,我们如何访问它?

Its not a parameter, its actually just a 'getter' function, that is declared in https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/parameters.rb 它不是参数,实际上只是一个“ getter”函数,在https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/parameters.rb中声明

So calls to params[:something] is really a method call which returns a hash, from which you access the http parameters. 因此,对params [:something]的调用实际上是一个返回哈希值的方法调用,您可以从该哈希值访问http参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM