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 8513061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:27:05+00:00 2026-06-11T04:27:05+00:00

OK, stupid newbie question: how do you make a line break only when it’s

  • 0

OK, stupid newbie question: how do you make a line break only when it’s needed?

I’m creating a basic address listing and only want to include a line of an address if it isn’t blank. How do I keep the blank line from printing? I’ve tried including the break and new line tags, and tried using puts and quotation marks of both varieties and escaping the slashes but can’t seem to display the address correctly.

Is there a way to have each line of the address to print on its own line or simply omit the line if there is no info to put on it?

Here’s the current version of the code:

<p><strong>Main Address</strong></p>
    <p><%= if @vendor.address1 || null
             @vendor.address1  #need a break here
           end %>
      <%= if @vendor.address2 || null
             @vendor.address2 #need a break here
           end %>
      <%= @vendor.city %>, <%= @vendor.state %> <%= @vendor.zip %></p>
  • 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-06-11T04:27:07+00:00Added an answer on June 11, 2026 at 4:27 am

    This is how I would do it:

    <p>
      <strong>Main Address</strong>
    </p>
    <p>
    <% unless @vendor.address1.blank? %>
      <%= @vendor.address1 %><br>
    <% end %>
    <% unless @vendor.address2.blank? %>
      <%= @vendor.address2 %><br>
    <% end %>
      <%= @vendor.city %>, <%= @vendor.state %> <%= @vendor.zip %>
    </p>
    

    By the way: the || null in your code is not valid Ruby. null does not exist, it should be nil. But even if you had used nil, your code does not do what you expect it to do. For these kind of things, you’d better use blank?.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if the question is stupid but I'm newbie to MySQL and got stuck
Newbie (perhaps stupid) question: How can I use the value of alt in the
Stupid question and treat me as completely a newbie to version control. I'm new
I'm a newbie to SQL and .Net and this question might be stupid too
Apologies if this is a stupid question - I'm an Android and Ant newbie.
This must be a very stupid newbie question, but I have spent my whole
1:sorry for this stupid question, but I am newbie in coding and this is
I'm newbie to WPF, and maybe ask some stupid question. However. I have a
Good day, friends. Once again stupid question about Obj-C from newbie :) I'm trying
This is probably a really stupid newbie-sounding question to you developer type people, but

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.