首页 > 在helper里写了一个方法,想用一个button去触发执行,请问用button_to 还是link_to, 后边的参数应该如何配。

在helper里写了一个方法,想用一个button去触发执行,请问用button_to 还是link_to, 后边的参数应该如何配。

写了一个方法,最好放在helper里,放到controller里也可以。 现在想知道在view里的button如何触发执行它 。谢谢大家给点意见。


button不会触发helper方法,button是发送http请求,因此只有合法的rest请求去执行controller里面的action.如果你的意思是客户端button触发,那是button的onclick事件,由js执行,helper是服务器端方法。plus:helper一般作为render view的过滤器来使用,当然也可以在controller里用,只是需要inlcude。因此,如果你是希望button请求最终会调用helper方法,那就把helper类include进controller,然后在你的action里面调用他即可。

【热门文章】
【热门文章】