ruby – 将局部变量传递给控制器??的视图
发布时间:2020-12-17 04:35:55 所属栏目:百科 来源:网络整理
导读:我无法出于某种原因将局部变量传递给show视图…… 在我的控制器中我简单地说: def show render template: "books/show",:resource = "Some text"end 在我看来,我打印以下内容: h1My local variable text: %= resource %/h1 我收到以下消息: undefined loc
我无法出于某种原因将局部变量传递给show视图……
在我的控制器中我简单地说: def show render template: "books/show",:resource => "Some text" end 在我看来,我打印以下内容: <h1>My local variable text: <%= resource %></h1> 我收到以下消息: undefined local variable or method `resource' for #<#<Class:0x00000118ebce90>:0x00000118ec3498> 我在控制器中尝试了以下语法: render template: "books/show",locals: { resource: "Some text" } render template: "books/show",locals: { resource => "Some text" } render template: "books/show",:locals => { resource: "Some text" } render template: "books/show",:locals => { resource => "Some text" } 没有运气…… 有什么线索吗? 谢谢! 解决方法
我认为它应该是这样的
渲染’books / show’,:locals => {:resource => ‘有些文字’} 这个对我有用 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |