Ruby on Rails 3.

I’m kind of new to Ruby on Rails and studied well, but it seems to have run into a problem that I can’t solve.

Running Rails 3.0.9 and Ruby 1.9.2

In my view, I run the following statement:

<%= @events.each do |f| %> <%= f.name %><%= link_to "View", event_path(f) %><br/><hr/> <% end %> 

And this is in my controller:

 class AdminController < ApplicationController def flyers @events = Event.all end end 

This goes through each of the records and displays the corresponding name, but the problem is that in the end it displays all the information for all the records, for example:

  [#<User id: 1, username: "test account", email: " test@gmail.com ", password_hash: "$2a$10$Rxwgy.0ZEOb0lMGEIliPBeB/jPSp8roeKdbMvXcLi32R...", password_salt: "$2a$10$Rxwgy.0ZEOb0lMGEIliPBe", created_at: 2111359287.2303703, updated_at: 2111359287.2303703, isadmin: true>] 

I am new to this site, so I'm not sure if you need more information, but any help is appreciated, in the end I am still involved.

Thanks in advance.

+7
source share
2 answers

You should use <% , not <%= for your .each line, so

 <%= @events.each do |f| %> 

it should be

 <% @events.each do |f| %> 
+13
source

.each returns the entire array at the end after loop completion. <%= ... %> displays the value of the statute, which is the value returned by .each <% ... %> no. So you want:

 <% @events.each do |f| %> <%= f.name %><%= link_to "View", event_path(f) %><br/><hr/> <% end %> 
+9
source

All Articles