Suppose I have a model, ‘Associate’, and it has a string member,
‘branch’. Sometimes branch can end with a percent sign (%) and
sometimes not.
I have a form to display the Associate data. In the branch field, I am
simply putting whatever text is in branch, before (to the left of) the
input box. In the input box itself, I either want to show the % sign
if branch ends in %, or, nothing.
How can I specify this? Below is my stab at it – SUppose the branch
is ‘34%’ , Of course, the way I have it, what shows in the text box is
the full branch of 34%, wherein, in this case, it should just be %.
<% form_for @associate do |f| %>
<%= f.label @associate.branch.split("%") %><%=
f.text_field :branch %>
<% end %>
(In my model, I have a before_save. which will set branch to that
original portion of branch left of the %, plus whatever is in the text
box. In so doing, no one can ever bring themselves up the branch-
coding tree, see?) -JannaB