<li style="width:190px" id="mobile_no_div"> <% if @user.carrier_id.nil? or @user.carrier_id == 0 %> <% else -%> <%=@user.carrier.name%> <%=@user.mobile_no%> <% end -%> </li>
Refactorings
No refactoring yet !
chalkers
June 12, 2008, June 12, 2008 10:20, permalink
<li style="width:190px" id="mobile_no_div"> <%=@user.carrier.name + " " + @user.mobile_no if !@user.carrier_id.nil? && @user.carrier_id > 0 -%> </li>
Simon
June 12, 2008, June 12, 2008 13:41, permalink
i think this is okay.
why draw an empty list item?
<%= '<li style="width:190px" id="mobile_no_div">' << @user.carrier.name << " " << @user.mobile_no << "</li>" unless @user.carrier_id.nil? && @user.carrier_id == 0 -%>
Simon
June 12, 2008, June 12, 2008 13:42, permalink
i made a typo lol && should be ||
<%= '<li style="width:190px" id="mobile_no_div">' << @user.carrier.name << " " << @user.mobile_no << "</li>" unless @user.carrier_id.nil? || @user.carrier_id == 0 -%>
danielharan
June 12, 2008, June 12, 2008 15:47, permalink
having carrier_id == 0 in the view smells. what does that mean? Is there a mysql default that's polluting data?
<% if @user.carrier? %>
<li style="width:190px" id="mobile_no_div">
<%= @user.carrier.name %> <%= @user.mobile_no %>
</li>
<% end %>
RickDumminic
June 14, 2008, June 14, 2008 04:53, permalink
<li style="width:190px" id="mobile_no_div"> <%= @user.mobile_no && @user.carrier && @user.carrier.name && (@user.carrier.name + " " + @user.mobile_no) || " " %> </li>
RickDumminic
June 14, 2008, June 14, 2008 04:55, permalink
Woops, missed ()
<li style="width:190px" id="mobile_no_div"> <%= (@user.mobile_no && @user.carrier && @user.carrier.name && (@user.carrier.name + " " + @user.mobile_no)) || " " %> </li>
Below is the small part of my RHTML page.
- I am just showing the mobile number with carrier on user profile page.
- users table has mobile_no and carrier_id(foreign key)as columns .
- If user doesn't have his/her mobile no then in users table mobile_no field will be null and carrier_id will be 0. On profile page I am just keeping blank.
- Following is the code that I am using .
Can it be re factor.
Thanks in advance