Warning - another newbie question - feel free to assume absolute ignorance. /grin/ I''m working on some customer managment screens right now. Customers can have many lines in their address: Customer Business and Technology Park 1 Main Street Suite 300 City, ST Zip+4 The model/table has (address_1, address_2, address_3). But it''s more common just to see one line: Customer 1 Main Street City, ST Zip+4 On the Show screen, I''d like to see it shown as I just typed it above instead of seeing all the empty lines (with <br>''s) after them: Customer 1 Main Street City, ST Zip+4 What''s the "elegant" way to do that? Thank you! -- 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 -~----------~----~----~----~------~----~------~--~---
don''t know, if it''s the perfect way, but i would do it something like that: <%= "#{@customer.address_1"}<br />" if @customer.address_1 -%> <%= "#{@customer.address_2"}<br />" if @customer.address_2 -%> <%= "#{@customer.address_3"}<br />" if @customer.address_3 -%> -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Muller wrote:> don''t know, if it''s the perfect way, but i would do it something like > that: > > <%= "#{@customer.address_1"}<br />" if @customer.address_1 -%> > <%= "#{@customer.address_2"}<br />" if @customer.address_2 -%> > <%= "#{@customer.address_3"}<br />" if @customer.address_3 -%>That will work. Thank you very much. I was trying: <%= (@customer.address_1 + ''<br />'') if @customer.address_1 -%> Which didn''t work correctly, of course. Would you mind explaining why "#" is at beginning and why the double-quotes are places where they are? Thank you very much for your help and your patience. -- 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 -~----------~----~----~----~------~----~------~--~---
Denise Robinson wrote:> Thorsten Muller wrote: >> <%= "#{@customer.address_3"}<br />" if @customer.address_3 -%>OK.... So, that syntax didn''t work for me. I changed a little and this does work: <%= (customer.address_1 + "<br />") if customer.address_1 -%> But, when I say it "works" I only mean that it will run and display a page. I still have the line breaks for some reason. Is there a way to give two options? Maybe I could try: if customer.address_1.empty? do this otherwise do this /shrug/ Just a thought. But maybe it''s just my syntax... -- 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 -~----------~----~----~----~------~----~------~--~---
sure, easy enough: you have a string, then you can place ruby-stuff in it with #{} so if you have a var @foo=''text'' then "<li>#{@foo}</li>" will end up as "<li>text</li>" in the above case it''s just an easy way to have the ''whole thing'' in one call and it keeps long string concatinations more readable (but your try looks good enough to me, i don''t see, why it should not work) just see a typing error, that''s the correct version (one double-quote less within the curly braces): <%= "#{@customer.address_1}<br />" if @customer.address_1 -%> -- 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 -~----------~----~----~----~------~----~------~--~---
For some reason, it still gives me the breaks. Here''s what I have: <p><h1><%= link_to company[:name], :action => :edit, :id => @company %></h1> <%= "#{@company.address_1}<br />" if @company.address_1 -%> <%= "#{@company.address_2}<br />" if @company.address_2 -%> <%= "#{@company.address_3}<br />" if @company.address_3 -%> <%= company.city %> , <%= company.state %> <%= company.zip %>-<%= company.zip4 %></p> And here''s what I end up with: Advanced Opitronic Devices (China) Co., Ltd. East YuQing Street High-Tech Zone Weifang , Shandong 261061- On the other hand, this works, but it''s ridiculously verbose: <% if company.address_1.empty? %> <%else%> <%= "#{@company.address_1}<br />" %> <% end %> <% if company.address_2.empty? %> <%else%> <%= "#{@company.address_2}<br />" %> <% end %> <% if company.address_3.empty? %> <%else%> <%= "#{@company.address_3}<br />" %> <% end %> <% if company[:state].empty? %> <%= company[:city] %> <% else %> <%= (company[:city] + '', '' + company[:state]) %> <% end %> <% if company[:zip4].empty? %> <%= company[:zip] %> <% else %> <%= (company[:zip] + ''-'' + company[:zip4]) %> <% end %><br/> <%= company[:country] %></p> -- 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 -~----------~----~----~----~------~----~------~--~---
And thanks for the syntax explanation, by the way. Every little syntax thing I can learn is such a big help right now. :) -- 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 -~----------~----~----~----~------~----~------~--~---
pardon me, but what''s the significance of -%> instead of the usual %> On Nov 15, 6:26 am, Thorsten Muller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> <%= "#...@customer.address_1}<br />" if @customer.address_1 -%>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
rubynuby wrote:> pardon me, but what''s the significance of -%> instead of the usual %> > > On Nov 15, 6:26 am, Thorsten Muller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>there''s a rule somewhere: use a dash to remove a line break after the ruby code It''s in one of my books somewhere.... -- 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 -~----------~----~----~----~------~----~------~--~---
Denise Robinson wrote:> rubynuby wrote: >> pardon me, but what''s the significance of -%> instead of the usual %> >> >> On Nov 15, 6:26 am, Thorsten Muller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > there''s a rule somewhere: use a dash to remove a line break after the > ruby code > > It''s in one of my books somewhere....Found it! Page 41 of Agile Web Development with Rails says: "Normally, this doesn''t matter, because HTML doesn''t much care about whitespace. However, if you''re using this templating mechanism to create emails, or HTML within <pre> blocks, you''ll want to remove these blank lines. Do this by changing the end of the ERb sequence to %> to -%>. That minus sign tells Rails to remove any newline that follows from that output. In general, suppressing these newlines is a matter of taste, not necessity. However, you will see Rails code out in the wild that uses the minus sign this way, so it''s best to know what it does." Since, I was have line break issues, I tried including the minus sign. -- 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 -~----------~----~----~----~------~----~------~--~---