我正在编写一个帮助程序,它将一个HTML属性添加到rails中的link_to标记.所以,我的想法是我的帮助器方法应该接受传递给它的任何参数或块,使用相同的参数调用link_to,将它的属性添加到返回的内容,并将结果返回给调用者.
像这样:
def link_to(*args, &block)
... rails code in link_to ...
end
def myhelper(*args, &block) # Notice that at this point, 'args' has already
link_to() # become an array of arguments and 'block' has
... my code ... # already been turned into a Proc.
end
myhelper() # Any arguments or blocks I pass with this call should make
# it all the way through to link_to.
Run Code Online (Sandbox Code Playgroud)
所以,正如你所看到的,似乎没有办法(不涉及大量的代码和条件分支)将myhelper收到的内容传递给link_to,而没有将所有参数恢复到它们到达之前的状态我的方法.
这个问题是否有更"类似Ruby"的解决方案?