简体   繁体   English

rails从视图将参数作为字符串传递给另一个控制器

[英]rails passing parameter from view to a different controller as a string

Im trying to pass a parameter (a file path : eg. user/lauren/tools/ ) from a view in RAILS to another different controller using RUBY. 我试图使用RUBY从RAILS中的视图传递参数(文件路径:例如user/lauren/tools/ )到另一个不同的控制器。 I want to use the file path (as a string) to be matched with a regular expression. 我想使用文件路径(作为字符串)与正则表达式匹配。 To do that, right now Im using the params [:parameter] method as follows in the controller action where Im setting the variable instance: 为此,现在Im在控制器操作中使用params [:parameter]方法,如下所示,其中Im设置变量实例:

@variable = /^.+\/[^\/]+$/.match(params[:name]).to_s ---where :name is the parameter passed from view

Right now, I dont get any output when I try to display that in the corresponding view of that controller....im guessing its the params [:name] method I need to replace or modify? 现在,当我尝试在该控制器的相应视图中显示该输出时,我没有得到任何输出。...我猜想它的params [:name]方法需要替换或修改吗?

Id really appreciate views on this...thanks! 我非常感谢对此的看法...谢谢!

While your server is running open a new terminal window and type rails console. 在服务器运行时,打开一个新的终端窗口,然后键入rails console。 This will let you see what your variables actually contain. 这将使您看到变量实际包含的内容。 You can type params and see what the hash has in it and see why your regex is failing. 您可以键入params并查看其中包含的哈希值,并查看正则表达式失败的原因。 It sounds to me like you are trying to match your path, not your params. 在我看来,您正在尝试匹配自己的道路,而不是参数。

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

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