On Dec 2, 2013, at 5:16 PM, yinwen Xuan wrote:
> Colin Law wrote in post #1129260:
>> On 2 December 2013 21:22, yinwen Xuan <lists@ruby-forum.com> wrote:
>>> could you just check why the ruby script not work
>>
>> Why should I help when you have not followed my request not to top
>> post and to remember to quote the previous reply?
>>
>>>
>>> it work when only use the field name : <%= land_area_unit -%>
>>>
>>> because the the field display not right, when its sqm, it show M2 I want
>>> it show m, that's why I want to write a if statement to showing the
>>> right unit format:
>>>
>>> <%= if land_area_unit == M2 %>m² <% else %> <%= if land_area_unit
>>> == HA %>Ha <% else %><%= if land_area_unit == AC %>Ac<% else %>f²
>>
>>
>> There are so many things wrong I don't know where to start. Have a
>> look at
>> http://www.howtogeek.com/howto/programming/ruby/ruby-if-else-if-command-syntax/.
>>
>> What is ² intended to be? Should it be ² perhaps.
>>
>> What are the variables M2 and H2 set to?
>>
>> Colin
>
> Hi Colin,
>
> I do want to do what you request, but as I explain that I can't edit the
> server, view controller etc
> the original code on the themes is:
> <%= land_area -%><%= land_area_unit -%>
> it show on website is 1234 M2
> what I want to do is change the M2 to m²
> m² is html to display m² , then I change it to:
>
> <%= land_area -%><%= if land_area_unit == M2 %> m² <% else %>Ha
>
> Ha is Hectares
> but its not work, sorry that I can't do too much following what you
> request because I don't know how.
> 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
--
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/41667AFA-B7ED-49F9-8411-CD27C9C2ACE6%40wdstudio.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment