Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6195973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:33:46+00:00 2026-05-24T03:33:46+00:00

PART 1: The below code seems to work fine, but there must be a

  • 0

PART 1: The below code seems to work fine, but there must be a better way to do the second line. This is to display a user address. It is pretty simple, where if there is content for the second line of an address, I output that and a line break.

      <%= @sponsor.address1 %><br />
      <%= raw "#{@sponsor.address2} <br />" unless @sponsor.address2.empty? %>
      <%= @sponsor.city %>, <%= @sponsor.state %> <%= @sponsor.zip %>

Is there some obvious, more elegant way to do this?

PART 2: What if the value may also be nil? Should I handle that in the model? Is there some simple way to have a model return blank instead of nil?

Nesting this in yet another condition seems too messy. Can someone tell me the best rails way to accomplish part 1 and/or 2 above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:33:47+00:00Added an answer on May 24, 2026 at 3:33 am

    Few more options if you want to make the div conditional too;

    <%= content_tag :div do -%>
      @sponsor.address2
    <% end if @sponsor.address2? -%>
    

    or

    <%= content_tag :div, @sponsor.address2 if @sponsor.address2? %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is an exception being thrown in the f++ part of the code below
below is part of html code <div id=test1><span><input type='text' name='add'/><input type='text' name='del'/><span></div> <div id=container></div>
Below is part of the XML which I am processing with PHP's XSLTProcessor :
Part of my everyday work is maintaining and extending legacy VB6 applications. A common
Part of a new product I have been assigned to work on involves server-side
I have this curl request below, which was successfully troubleshooted in another post. Right
Part of the install for an app I am responsible for, compiles some C
Part of our java application needs to run javascript that is written by non-developers.
Part of the series of controls I am working on obviously involves me lumping
Part of the setup routine for the product I'm working on installs a database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.