简体   繁体   中英

Can't get the information from database

I'm new to Ruby on Rails and to learn it I'm trying to make a simple application without scaffolding.

I generated a controller Foos, a model Foo and created 4 foos in the database. Then I tried to get /Foos/ and got an error. So I wrote

def index
    @foos = Foo.all
end

in the controller and created a view.

The view looks like

<% @foos.each do |foo| %>
    <div><% foo.name %></div>
<% end %>

The logs from console and from the server looks the same

Processing by FoosController#index as HTML
Foo Load (0.1ms)  SELECT "foos".* FROM "foos"

But when I get Foos from the rails console it shows me foos and the view just creates 4 empty divs. Why? Did I miss something?

<% @foos.each do |foo| %>
    <div><%= foo.name %></div>
<% end %>

You need equal sign for output to the view

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM