NoobOnRails

Ruby on Rails tips, tricks and hints for the aspiring rails hero.



Saturday, December 17, 2005

A quick tidbit on working in a view


If you're working in a view and you wondering why your...

<% for person in @people %>

<% person.name %>

<% end %>

...isn't showing the name of that person as stored in your database (you may not get an error), it's not because the app isn't working right. You're just not telling it to convert the raw data it's getting from the db. You need to modify the

<% person.name %>

line to look like this

<%= person.name %>

The = sign tells Rails to turn that value into a string. If the data is a string, it will be displayed on your page. Voila!

1 Comments:

  • At 4:44 PM, Blogger tomoj said…

    Actually, the view just outputs the result of ruby code in between <%= and %>. No converting. Ruby code between <% and %> doesn't output anything.

     

Post a Comment

<< Home