I've got a Ruby on Rails app where I do the following:
@user = User.find(:first, :conditions => ['LOWER(username) = ?', current_subdomain.downcase], :include => :bio)
Where ':include => :bio' is the important part.
Then in the view I want to display some bio:
<em><%= @user.bio.title %></em><br />
<%= @user.bio.city %><br />
<%= @user.bio.state %><br />
<%= @user.bio.country %>
But if the user dosn't have any information it just will turn up a couple of blank rows.
I've tried a couple of different things, none has worked so far...
<% if @user.bio.title %> # is always true
<% if @user.bio.title > 0 %> # triggers an error if @user.bio.title isn't set
<% unless @user.bio.title.empty? %> # same as above
Any sollution to how to just display the data the user has got?
Thanks in advance!
UPDATE
Ok, if figured some things out:
<% if @user.bio.title %> # Works if the bio isn't set at all.
<% if @user.bio.title > 0 %> # Works if the bio is set.
So I can use a sollution that looks like:
<% if @user.bio.title %><% if @user.bio.title > '0' %><%= @user.bio.title %><% end %><% end %>
But it seam a little overkill? Any better suggestions?
Thanks!