Shauna Haines wrote:
I have a select box with the options stored in a constant in my model,
e.g.
TRANS_CODES = [
[“PM Payment – Regular”, “pm”],
[“PX Payment – Regular, but skip periodic TA fee”, “px”],
[“LP Late Payment – made after charges were posted”, “lp”],
…
It works fine except that the little gap between, say, PM and the
following explanation disappears. How can I create a non-breaking space
between the codes and their explanations? Multiple spaces and tabs all
reduce to a single space. I tried “PM” + “ ” + … but all my
attempts got syntax errors.
Help!
TIA,
Shauna
I haven’t had much luck playing with this and getting the select helper
to do what you want. However, keep in mind that you don’t have to always
use the helpers - you can build a SELECT of your own “by hand”, so to
speak…
Say you change your TRAN_CODES so it looks like this:
TRANS_CODES = [
[“PM”, “Payment – Regular”,
“pm”],
[“PX”, “Payment – Regular, but skip periodic TA fee”,
“px”],
[“LP”, “Late Payment – made after charges were posted”,
“lp”]]
Then you could do something like this and it would look the way you
want:
<select id="object_method" name="object[method]">
<% TRANS_CODES.each do |tc| %>
<option value="<%= tc[2] %>"<%= ' selected="selected"' if
@object.method == tc[2] %>><%= tc[0] + ’ ’ +
tc[1] %>
<% end %>
Replace “object” with the name of your model and “method” with the name
of the attribute this field populates. If you have a lot of these, you
could build your own helper to do it.
One big caveat - even getting it to work, unless you use a monospace
font for the dropdown, the spaces are not going to line up perfectly
like (I think) you want, and it’s going to look uneven.
c.