Rendering issue in views in 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. ? 回答1: <% @array_bookmark = @bookmark.class == Array ? @bookmark : [@bookmark] %> <% @array_bookmark.each do |book| %> 回答2: Just wrap @bookmark in Array() , like this: <% Array(@bookmark).each do |book| %> Incidentally you should