[英]How to iterate a text value to Active Record Model name format in ruby on rails?
[英]Ruby on Rails Active record object
我有一个用户 model 并与 Note model 有 has_many 关联。 以数组格式获取记录。 我必须只显示内容(笔记模型列)。 因此,使用以下方法获取数据:
@user.notes.pluck(:content).
它是这样给予的。
["Testing Notes123", "Testing Notes12345"].
在 UI 我想这样显示:
Testing Notes123
Testing Notes12345
有人可以帮我解决这个问题。
“用户界面”是指 web 页面吗? 这将涉及 controller 和视图。 如果您只是在谈论控制台,那么应该这样做:
notes = @user.notes.pluck(:content)
notes.each do |note|
puts note
end
或者:
notes = @user.notes.pluck(:content)
puts notes.join("\n")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.