0

我的控制器中有索引方法,有一行:

@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>] 

我不明白为什么这是输出

4

1 回答 1

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.

来源

于 2013-09-12T13:54:56.730 回答