i have a real simple one today.. here''s how it works. i have a field called address2 that is in most cases, blank.. the rhtml that does this looks like: <%= place[:address1] %><br/><%= place[:address2] %><br/><%= place[:city] %>, <%= place[:state] %> <%= place[:zip] %> what i would like to do is only print address 2 if it exists.. otherwise, blank.. is there a class method that does this? thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
If place[:address2] is nil or empty string then <%= place[:address2] %>
should work. But I just noticed those <br /> tags... You''ll
probably want to
do something more like <%= "<br />#{place[:address2]}<br
/>" unless
place[:address2].blank? %>. If you''ve got an aversion to putting the
HTML up
inside the Ruby there, you could write this out as block
<% if place[:address2] -%>
<br /><%= place[:address2] %><br />
<% end -%>
but it''s so short I''d just stick with embedding the HTML in
the [embedded]
Ruby.
RSL
On 2/16/07, Sergio Ruiz
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> i have a real simple one today..
>
> here''s how it works.
>
> i have a field called address2 that is in most cases, blank..
>
> the rhtml that does this looks like:
>
> <%= place[:address1] %><br/><%= place[:address2]
%><br/><%= place[:city]
> %>, <%= place[:state] %> <%= place[:zip] %>
>
>
> what i would like to do is only print address 2 if it exists..
>
> otherwise, blank..
>
> is there a class method that does this?
>
> thanks!
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---
a helper would be nice for something like this.
def address_block()
address = []
address << block[:address1]
address << block[:address2] unless block[:address2].blank?
address << block[:city] + ", " + block[:state] + " "
+ block[:zip]
address.join("<br/>")
end
then in view:
<%= address_block(place) -%>
now your view is nice and clean
On 2/16/07, Sergio Ruiz
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> i have a real simple one today..
>
> here''s how it works.
>
> i have a field called address2 that is in most cases, blank..
>
> the rhtml that does this looks like:
>
> <%= place[:address1] %><br/><%= place[:address2]
%><br/><%= place[:city]
> %>, <%= place[:state] %> <%= place[:zip] %>
>
>
> what i would like to do is only print address 2 if it exists..
>
> otherwise, blank..
>
> is there a class method that does this?
>
> thanks!
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---
should have been def address_block(block) On 2/16/07, Chris Hall <christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> a helper would be nice for something like this. > > def address_block() > address = [] > address << block[:address1] > address << block[:address2] unless block[:address2].blank? > address << block[:city] + ", " + block[:state] + " " + block[:zip] > address.join("<br/>") > end > > then in view: > > <%= address_block(place) -%> > > now your view is nice and clean > > On 2/16/07, Sergio Ruiz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > i have a real simple one today.. > > > > here''s how it works. > > > > i have a field called address2 that is in most cases, blank.. > > > > the rhtml that does this looks like: > > > > <%= place[:address1] %><br/><%= place[:address2] %><br/><%= place[:city] > > %>, <%= place[:state] %> <%= place[:zip] %> > > > > > > what i would like to do is only print address 2 if it exists.. > > > > otherwise, blank.. > > > > is there a class method that does this? > > > > thanks! > > > > -- > > 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 -~----------~----~----~----~------~----~------~--~---
Chris Hall wrote:> a helper would be nice for something like this. > > def address_block() > address = [] > address << block[:address1] > address << block[:address2] unless block[:address2].blank? > address << block[:city] + ", " + block[:state] + " " + block[:zip] > address.join("<br/>") > end > > then in view: > > <%= address_block(place) -%> > > now your view is nice and cleanvery nice.. i put all these into my code, and it worked! thanks, all! -- 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 -~----------~----~----~----~------~----~------~--~---