It may be better to do it in the controller anyway, keep the view as
simple as possible. In the controller setup @units as appropriate and
then just display it in the view. Logic in the view is best avoided
wherever possible.
Hi Colin, Thanks for your advice,
but I can't access to the rails server, only can edit the ruby script.
any chance you can check anything wrong with the If statement script?
What do you mean you only have access to the ruby script? The script
you showed is in the view, which runs on the server. I am suggesting
that you change it in the controller ruby script instead of the view
ruby script.
I mean I can't edit the server, like view controller.
I only can edit the html themes, check the attachment for the screen
shot
sorry, I am a beginner and just want do some maintaining
cheers
Please don't top post, and please quote the previous message.
Remember this is a mailing list, not a forum, though you may be
accessing it through a forum like interface.
I mean I can't edit the server, like view controller.
I only can edit the html themes, check the attachment for the screen
shot
sorry, I am a beginner and just want do some maintaining
cheers
Sorry, I have no idea what theme you are trying to adjust. Presumably
you are using some application with configurable themes. I think you
had better give us some more information about your environment.
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²
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²
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²
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:
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.
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² <%
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²<%-
else %><%= land_area_unit %><%- end %>
Which could arguably be written a lot more neatly:
Hi Walter, your first script is working!! that's great!!!
since the land unit got three others:
AC - Acres
HA - Hectares
F2 - Sq feet
Then I extend your code to the follow, but not working
Land Area: <%= land_area %>
<%- if land_area_unit == 'M2' %>m²
<%- else %><%- if land_area_unit == 'HA' %>Ha
<%- else %><%- if land_area_unit == 'AC' %>Ac
<%- else %>f²<%- end %>
Seriously, you need to work through a tutorial, as suggested earlier, rather than expect the members of this forum to write your code one statement at a time.
And when you take the time to work through a tutorial, you'll learn about "elsif"
Seriously, you need to work through a tutorial, as suggested earlier,
rather than expect the members of this forum to write your code one
statement at a time.
Sorry and thanks! I did go through the tutorial and edit my code as
this:
Land Area: <%= land_area %>
<%- if land_area_unit == 'M2' %>m²
<%- elseif land_area_unit == 'HA' %>Ha
<%- elseif land_area_unit == 'AC' %>Ac
<%- else %>sq feet<%- end %>
but the result is all showing sq feet, any idea, sorry I don't know
where else I can work it out.
One last thing, regarding people who told you to move this from view to controller, and your response that you have no access to the files on the server. This file that you are editing is on the server. It is in the same folder hierarchy as the controller. It is very unlikely you have access to this RoR view file but not the RoR controllers or models.