helper_method

helper的方法可以在view直接调用,而controller就不行。

那么,怎么让view访问到controller定义的hepler呢?

在controller中用helper_method定义属性,就可以在view中使用。

view_context

在controller中不能直接调用helper方法,那应该通过什么方式调用呢?

使用view_context。

总结

不过还是建议controller和helper之间不要相互调用方法,让view归view,controller归controller,这样就不会太乱。

参考资料:http://blog.xdite.net/posts/2014/06/16/helper-method-and-view-context

results matching ""

    No results matching ""