ruby-on-rails – AssetTagHelper :: image_path外部视图
发布时间:2020-12-17 04:24:43 所属栏目:百科 来源:网络整理
导读:据推测,ActionController :: Base.helpers就像一个代理,用于访问视图外的助手.然而,那里定义的许多方法依赖于控制器变量,我无法成功调用: ActionController::Base.helpers.image_path("my_image.png") TypeError Exception: can't convert nil into String
据推测,ActionController :: Base.helpers就像一个代理,用于访问视图外的助手.然而,那里定义的许多方法依赖于控制器变量,我无法成功调用:
ActionController::Base.helpers.image_path("my_image.png") >> TypeError Exception: can't convert nil into String 在源头挖掘我看到compute_asset_host方法试图访问config.asset_host但是配置为nil. 如何从外部视图成功调用image_path? 解决方法
使用view_context访问视图中可用的辅助方法.
您可以从控制器中调用image_path. view_context.image_path "my_image.png" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |