【发布时间】:2014-07-15 15:25:44
【问题描述】:
我在app/helpers/posts_helpers.rb 中有一个自定义助手:
module PostsHelper
def custom_helper(post)
#do something
end
end
当我从一个视图调用它时,我得到了错误:
ActionView::Template::Error (undefined method 'custom_helper' for class..
但如果我从app/helpers/application_helper.rb 调用相同的助手如下,那么视图能够检测到助手。
module ApplicationHelper
def custom_helper(post)
#do something
end
end
即使在config/application.rb 中默认设置为 true,甚至尝试将 include all helper 选项显式设置为 true。这也没有帮助。
config.action_controller.include_all_helpers = true
为什么没用?
【问题讨论】:
标签: ruby-on-rails-4 view-helpers