gpt4 book ai didi

ruby-on-rails - 将数组从 Controller 传递到 ruby​​ 中查看

转载 作者:数据小太阳 更新时间:2023-10-29 08:20:48 26 4
gpt4 key购买 nike

我的 Ruby Controller 中有以下代码:

ma​​stertest_controller.rb

def index

......

@mastertest = connection.execute("select code_ver from mastertest")
result_array = { sometihng }

......

respond_to do |format|
format.html # index.html.erb
format.json { render :json => @mastertest}
format.json { render :json => result_array}

end

但它只允许我在 View (index.html.erb) 中访问@mastertest。如何将数组传递给 View ???

最佳答案

Controller 中的实例变量在 View 中作为实例变量传递。

Controller :

@result_array = [something, second_something]

那么在你看来:

<% @result_array.each do |item| %>
<%= item %>
<% end %>

关于ruby-on-rails - 将数组从 Controller 传递到 ruby​​ 中查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12963458/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com