0

Im trying to pass a parameter (a file path : eg. user/lauren/tools/) from a view in RAILS to another different controller using RUBY. 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:

@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?

Id really appreciate views on this...thanks!

4

1 回答 1

0

当您的服务器正在运行时,打开一个新的终端窗口并输入 rails console。这将让您看到您的变量实际包含的内容。您可以键入 params 并查看其中包含的哈希值,并查看您的正则表达式失败的原因。在我看来,您正在尝试匹配您的路径,而不是您的参数。

于 2013-08-03T04:18:48.017 回答