简体   繁体   English

Ruby on Rails控制台

[英]Ruby on rails console

I have an issue with a nested model in my application. 我的应用程序中存在嵌套模型问题。 I can't get the values to show. 我无法显示这些值。 I know I have to do it like this: @modelname.attribute (view), but it doesn't seem to work. 我知道我必须这样做:@ modelname.attribute(视图),但是它似乎不起作用。 That's why I started to look in the console if everything I did in the controller was right. 这就是为什么我开始在控制台中查看我在控制器中所做的一切是否正确的原因。 Everything seems ok. 一切似乎还好。 But I have one question, in the console, when you do this (example): 但是当您执行此操作时,控制台中有一个问题(示例):

@modelname = Modelname.find(an id)

it gives you the corresponding object like this: 它为您提供了相应的对象,如下所示:

=>#< Modelname, id: x, other attributes >

and when I'm trying to find my other object in the console, I get this: 当我尝试在控制台中找到其他对象时,得到以下信息:

=>[#< Modelname, id: x, other attributes >]

Why? 为什么? What's the difference and could that be my problem? 有什么区别,这可能是我的问题吗?

The second time –in the console– you're getting an array. 第二次–在控制台中–获得了阵列。 That's the difference. 就是这样。 As of why, we don't know what your wrote to find the model, but you must be calling ModelName.where or one fo the other methods in the ActiveRecord query API that returns an array (an ActiveRecord::Relation to be precise) 因此,我们不知道您写了什么来查找模型,但您必须在返回数组的ActiveRecord查询API中调用ModelName.where或其他方法(准确地说是ActiveRecord :: Relation)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM