Ruby on Rails Monday, December 2, 2013

On Dec 2, 2013, at 8:33 PM, yinwen Xuan wrote:

> Walter Davis wrote in post #1129271:
>> On Dec 2, 2013, at 5:16 PM, yinwen Xuan wrote:
>>
>>>>> because the the field display not right, when its sqm, it show M2 I want
>>>>
>>> the original code on the themes is:
>>> and thanks in advance!
>> If you're trying to do a comparison, you need to quote the M2, since it
>> will be a string value, not a constant. Also, if you're doing a
>> comparison (which you don't want to output any value) then don't use <%=
>> %> as the container, rather <% %> or <%- %> so as to avoid outputting
>> the result of land_area_unit == 'M2', which would be 'true' some of the
>> time.
>>
>> Walter
>
> I tried this:
>
> Land Area: <%= land_area %> <%= if land_area_unit == M2 %> m&sup2; <%
> else %> <% end %>
>
> but not working

This is the same code I commented on, I don't see that you took up any of my suggestions here.

Land Area: <%= land_area %> <%- if land_area_unit == 'M2' %>m&sup2;<%-
else %><%= land_area_unit %><%- end %>

Which could arguably be written a lot more neatly:

Land Area: <%= "#{land_area} #{(land_area_unit == 'M2')? 'm&sup2;' : land_area_unit}".html_safe %>

Still quite a mess to have in your view, though.

Walter

>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f357ff60cfa96f4849285867f74dac7e%40ruby-forum.com.
> For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/275014E5-49C2-417A-B916-F1E21FFD0B89%40wdstudio.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment