Heroku 上的 Rails HABTM 模型显示“model_id”、“name”和“时间戳”而不是简单地“名称”
这一定很简单,但我就是找不到方法。
我有 2 个具有 HABTM 关系的模型。
Trip.rb
has_and_belongs_to_many :categories
Category.rb
has_and_belongs_to_many :trips
Trip index.html.erb
<%= trip.categories %>
在我的本地计算机上一切正常 - 我只看到类别名称。
但是当我部署到heroku时,我看到的不是类别名称,而是
[#<Category id: 1, name: "Surfing", created_at: "2011-10-20 12:28:57", updated_at: "2011-10-20 12:28:57">]
有人知道如何解决这个问题吗? 多谢!
This must be quite simple, but I just can't find a way.
I have 2 models with HABTM relationship.
Trip.rb
has_and_belongs_to_many :categories
Category.rb
has_and_belongs_to_many :trips
Trip index.html.erb
<%= trip.categories %>
everything is fine on my local machine - I see only the category name.
But when I deploy to heroku, instead of category name I see
[#<Category id: 1, name: "Surfing", created_at: "2011-10-20 12:28:57", updated_at: "2011-10-20 12:28:57">]
Anyone knows how to fix this ?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定为什么您会在本地看到
name
,但您在 Heroku 上看到的是to_s
在trip 上隐式调用的结果。 categories
关联,它是一个类别记录数组。但是您当前的模板仍然会将字符串
Array
放入输出中,例如:您可能想要的更像是:
这将导致:“category1、category2和category3”,或一些这样的。
I'm not sure why you would see the
name
locally, but what you're seeing on Heroku is the result ofto_s
being implicitly called on thetrip.categories
association, which is an array of category records.But your current template is still going to drop an
Array
of strings into the output, like:What you probably want is more like:
Which would result in: "category1, category2, and category3", or some such.