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 -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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, > ShaunaI 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] %></option> <% end %> </select> 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. -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, Cayce. I altered my TRANS_CODES definition as you suggested, then cut-and-pasted your select code into my new.rhtml view then replaced "object" with "payment" and "method" with "TransCode". Here''s my result: <li><select id="payment_TransCode" name="payment[TransCode]"> <% TRANS_CODES.each do |tc| %> <option value="<%= tc[2] %>"<%= '' selected="selected"'' if @payment.TransCode == tc[2] %>> <%= tc[0] + '' '' + tc[1] %></option> <% end %> </select></li> But when I tried to run it, the Action Controller attempted to stick in .to_s in a few places (maybe this is normal?) and got the following compile error: ... parse error, unexpected '')'', expecting kTHEN or '':'' or ''\n'' or '';'' if @payment.TransCode == tc[2] ).to_s); _erbout.concat ">\n" ^ (the carat is pointing to the dot right before to_s). Can you see what I did wrong? Thanks, Shauna -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Shauna Haines wrote:> Thanks, Cayce. > > I altered my TRANS_CODES definition as you suggested, then > cut-and-pasted your select code into my new.rhtml view then replaced > "object" with "payment" and "method" with "TransCode". Here''s my result: > > <li><select id="payment_TransCode" name="payment[TransCode]"> > <% TRANS_CODES.each do |tc| %> > <option value="<%= tc[2] %>"<%= '' selected="selected"'' > if @payment.TransCode == tc[2] %>> > <%= tc[0] + '' '' + tc[1] %></option> > <% end %> > </select></li> > > But when I tried to run it, the Action Controller attempted to stick in > .to_s in a few places (maybe this is normal?) and got the following > compile error: > > ... parse error, unexpected '')'', expecting kTHEN or '':'' or ''\n'' or '';'' > if @payment.TransCode == tc[2] ).to_s); _erbout.concat ">\n" > ^ > (the carat is pointing to the dot right before to_s). > > Can you see what I did wrong? > > Thanks, > ShaunaI think the problem is you are breaking an inline if statement across two lines. Where you have: <option value="<%= tc[2] %>"<%= '' selected="selected"'' if @payment.TransCode == tc[2] %>> You need to keep the if statement and what it applies to all together on one line without a break: <%= '' selected="selected"'' if @payment.TransCode == tc[2] %> c. -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Okay, that''s fixed, but now Action Controller complains about "uninitialized constant TRANS_CODES". I looked it over again and I''m pretty sure my syntax is as you outlined it. Here are the first few lines and the last two lines: TRANS_CODES = [ ["PM", "Payment -- Regular", "pm"], ["PX", "Payment -- Regular, but skip periodic TA fee", "px"], ["XX", "Manual Entry", "xx"] ].freeze Thanks again for helping, Shauna -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry, I did find my last problem: I needed to precede TRANS_CODES with Payment:: And you are correct, in a non-monotype font the spaces aren''t exactly right. But I can fiddle with that. Thanks for getting me past the logjam! Shauna -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Shauna Haines wrote:> Sorry, I did find my last problem: > > I needed to precede TRANS_CODES with Payment:: > > And you are correct, in a non-monotype font the spaces aren''t exactly > right. But I can fiddle with that. Thanks for getting me past the > logjam! > > ShaunaYep, you got it - Payment::TRANS_CODES - sorry about that it didn''t cross my mind. Glad to help. Bedtime. c. -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---