我正在尝试从我的控制器操作中渲染一些东西。
def show
@bookmark = Bookmark.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @bookmark }
end
end
以上是控制器中的操作。
show 的 html erb 文件是:
<p>
<b>Url:</b>
<%= @bookmark.each do |book| %>
<li><%= book.url%>
<b>Title:</b>
<li><%= book.title%>
<% end %>
</p>
我也得到了输出,但除此之外,我得到了额外的东西。输出是:
Url:
www.google.com Title:
h
www.gmail.com Title:
hiw
asd Title:
as
sd Title:
ad
asd Title:
as
asd Title:
as
asfa Title:
ada
www.mrabhiram.github.com Title:
abhi
www.mrabhiram.github.com Title:
abhi
www.mrabhiram.github.com Title:
abhi
[#<Bookmark id: 1, title: "h", url: "www.google.com", tags: "php,python", created_at: "2012-12-12 06:02:21", updated_at: "2012-12-12 06:02:21">, #<Bookmark id: 2, title: "hiw", url: "www.gmail.com", tags: "mail", created_at: "2012-12-12 06:02:41", updated_at: "2012-12-12 06:02:41">, #<Bookmark id: 3, title: "as", url: "asd", tags: "asd", created_at: "2012-12-12 06:07:41", updated_at: "2012-12-12 06:07:41">, #<Bookmark id: 4, title: "ad", url: "sd", tags: "dsfsd", created_at: "2012-12-12 06:11:04", updated_at: "2012-12-12 06:11:04">, #<Bookmark id: 5, title: "as", url: "asd", tags: "asd", created_at: "2012-12-12 06:22:36", updated_at: "2012-12-12 06:22:36">, #<Bookmark id: 6, title: "as", url: "asd", tags: "asda", created_at: "2012-12-12 06:25:33", updated_at: "2012-12-12 06:25:33">, #<Bookmark id: 7, title: "ada", url: "asfa", tags: "fa", created_at: "2012-12-12 07:41:16", updated_at: "2012-12-12 07:41:16">, #<Bookmark id: 8, title: "abhi", url: "www.mrabhiram.github.com", tags: "abhiram,php", created_at: "2012-12-12 07:45:29", updated_at: "2012-12-12 07:45:29">, #<Bookmark id: 9, title: "abhi", url: "www.mrabhiram.github.com", tags: "abhiram,php", created_at: "2012-12-12 07:46:19", updated_at: "2012-12-12 07:46:19">, #<Bookmark id: 10, title: "abhi", url: "www.mrabhiram.github.com", tags: "abhiram,php", created_at: "2012-12-12 07:48:28", updated_at: "2012-12-12 07:48:28">]
我最后应该摆脱数组打印。我只想打印记录。