은 내가 다음을 수행 루비 레일에 응용 프로그램을 가지고이되지 않을 수 있습니다모범 사례 사용자가
@user = User.find(:first, :conditions => ['LOWER(username) = ?', current_subdomain.downcase], :include => :bio)
'=> 포함 : 바이오'는 중요한 부분입니다.
그런 다음보기에서 좀 바이오 표시하려면 :
<em><%= @user.bio.title %></em><br />
<%= @user.bio.city %><br />
<%= @user.bio.state %><br />
<%= @user.bio.country %>
을하지만 사용자가 어떤 정보를 dosn't 경우는 빈 행의 몇 가지를 설정합니다. ...
<% 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
단지 사용자가 가지고있는 데이터를 표시하는 방법에 대한 모든 sollution이
나는 다른 몇 가지를 시도했습니다 아무도 지금까지 일을하지 않았다?
미리 감사드립니다.
UPDATE
좋아, 몇 가지를 알아 낸 경우 :
<% if @user.bio.title %> # Works if the bio isn't set at all.
<% if @user.bio.title > 0 %> # Works if the bio is set.
그래서 나는처럼 보이는 sollution 사용할 수 있습니다
<% if @user.bio.title %><% if @user.bio.title > '0' %><%= @user.bio.title %><% end %><% end %>
을하지만 약간의 과잉을 심? 더 좋은 제안이 있습니까?
감사합니다.
! 확실한 경우 더빙보다 좋습니다. 감사합니다. – Alfred
나는 여기서 대안을 좋아하고,보기 코드를 모델 코드로 끌어 낸다. –