ruby on rails 视图中的渲染问题 [英] Rendering issue in views in ruby on rails
本文介绍了ruby on rails 视图中的渲染问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
视图中的代码应给出数据库中的书籍
The code in the view shall give the books in the database
<% @bookmark.each do |book| %>
仅适用于多行.如果我有单行,它会显示像
works only for multiple rows. If i had single row, it would show error like
" undefined method `each' for #<Bookmark:0x3e2e3f0> "
我应该怎么做才能打印单行.?
What should i do to print single row also. ?
推荐答案
<% @array_bookmark = @bookmark.class == Array ? @bookmark : [@bookmark] %>
<% @array_bookmark.each do |book| %>
这篇关于ruby on rails 视图中的渲染问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文