我的控制器中有索引方法,我有一行:
@channels = Channel.where("user_id = ?", current_user.id)
我使用gem“Haml-rails”,我有这样的观点: 的 index.html.haml
- provide(:title, "Channels")
.offset1
= @channels.each do |channel|
Channel name:
= channel.name
%br
Url:
%a
= channel.url
%br
= link_to "Change", edit_channel_path(channel)
|
= link_to "Delete", channel, method: :delete,
data: { confirm: "Are you sure?" }
%br
它有效,但在视图中输出有关模型的信息:
[#<Channel id: 1, name: "tut.by", url: "http://tut.by/rss/rss.all", created_at: "2013-09-13 11:21:14", updated_at: "2013-09-13 11:21:14", user_id: 17>, #<Channel id: 2, name: "youtube.com", url: "http://youtube.com/rss/rss.all", created_at: "2013-09-13 11:54:50", updated_at: "2013-09-13 11:54:50", user_id: 17>]
我不明白为什么这是输出
答案 0 :(得分:3)
你应该改变
= @channels.each do |channel|
#The equals character is followed by Ruby code.
#This code is evaluated and the output is inserted into the document.
到
- @channels.each do |channel|
#The hyphen character is also followed by Ruby code.
#This code is evaluated but not inserted into the document.