我正在编写一个帮助程序,将HTML属性添加到rails中的link_标记中.因此,我的 idea 是,我的helper方法应该接受传递给它的任何参数或块,使用这些相同的参数调用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.
因此,正如您所看到的,似乎没有办法(不涉及大量代码和条件分支)将myhelper接收到的内容传递给link_,而不将所有参数返回到我的方法之前的样子.
对于这个问题,有没有更"像Ruby "的解决方案?