Igor  Biryukov
Igor Biryukov

Reputation: 270

Unnecessary information about model in views

I have index method in my controller, there is I have one line:

@channels = Channel.where("user_id = ?", current_user.id)

I use gem "Haml-rails" and I have view like this: 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

And it's works, but in view it output information about model:

[#<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>] 

I don't understand why this is output

Upvotes: 0

Views: 40

Answers (1)

dax
dax

Reputation: 10997

You should change

= @channels.each do |channel|
#The equals character is followed by Ruby code. 
#This code is evaluated and the output is inserted into the document.

to

- @channels.each do |channel| 
#The hyphen character is also followed by Ruby code. 
#This code is evaluated but not inserted into the document.

source

Upvotes: 3

Related Questions