简体   繁体   English

Ruby:如何将多个:locals传递给index.erb?

[英]Ruby: How do you pass in multiple :locals into index.erb?

    somevariable = "hello"
    answer = {yesorno: "yes"}
    anotheranswer = {whatisit: somevariable}
    erb :index, :locals => answer, anotheranswer

When I try to run the server it says : 当我尝试运行服务器时,它说:

syntax error, unexpected '\\n', expecting =>. 语法错误,意外的'\\ n',期望=>。

If I remove the anotheranswer from the locals, then it just passes in that one answer, and it works fine. 如果我删除anotheranswer从当地人,那么它只是在传递一个答案,并能正常工作。

How do I pass in multiple :locals ? 如何传递多个:locals

它们都必须在同一哈希中。

erb :index, :locals => { whatisit: somevariable, yesorno: "yes" }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我将如何引入Jquery项目以更新Sinatra中的index.erb? - How would I bring in Jquery items to update an index.erb in Sinatra? 如何将数组传递给 ruby 中的 erb 模板并对其进行迭代? - How do you pass an array to an erb template in ruby and have it iterated over? Ruby on Rails:如何在视图中显示“原始”erb标记? - Ruby on Rails: How do you display “raw” erb tags in views? 重定向到另一个模型的索引操作,从而查看index.erb-Rhomobile - Redirect to another model's index action, and hence view index.erb - Rhomobile js.erb文件由于无法从多个控制器传递局部变量而无法呈现局部 - js.erb files not rendering partials due to a failure to pass them locals from multiple controllers 每当我加载index.erb时ActiveRecord都会创建新对象 - ActiveRecord creating new objects every time I load the index.erb Ruby 模板:如何将变量传递到内联 ERB? - Ruby templates: How to pass variables into inlined ERB? 如何在Ruby on Rails中创建指向.html.erb文件的链接? - How do you create a link to a .html.erb file in Ruby on Rails? 您如何在 Rails 6 上使用/ERB Ruby 迭代一系列数字? - How do you iterate over a range of numbers with each do with/ ERB Ruby on Rails 6? 如何在Rails中的ruby中更新index.html.erb中的数据? - How to update data in index.html.erb in ruby on rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM