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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:26:54+00:00 2026-06-13T02:26:54+00:00

In my method via some calculations a get data, then i need to view

  • 0

In my method via some calculations a get data, then i need to view it in view, but if write

@ar.each do |a|

when i have only one record i get error, also when i have one error each is bad idea. So how to do this this?

So i have such code in method:

non_original = []
@articles.each do |a|
  non_original << get_non_tecdoc("LA44", 1, "KNECHT")
end
@non_original = non_original

get_non_tecdoc returns object, or nothing…

So in view i have:

-@non_original.each do |no|
      =no.brand
      =no.description
      =no.price
      =no.quantity

But what to do if @non_original has one record, then @non_original.each gives error. So how to do check in view? If @non_original has one record, than simple @non_original.brand etc, but if more than one, than use each loop?

  • 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-13T02:26:55+00:00Added an answer on June 13, 2026 at 2:26 am
    <%= debug @ar %>
    

    This will give you a nice YAML format to look at in your view (assuming ERB).

    EDIT: I believe this is what you want, since you’re not interested in debugging.

    In your controller, use the splat operator to convert a singleton element to an array (it doesn’t modify arrays):

    @ar = *@ar
    

    Then @ar.each will work as expected in your view.

    Alternatively, you could check in your view:

    <% if @ar.is_a?(Array) %>
      <% @ar.each ... %>
    <% else %>
      <%= @ar %>
    <% end%>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using jQuery getJSON method to get data from my database via some php
Via post (not get) method, i'mm getting id's in one file in php... How
I have a class that modifies data via some extension methods. In order to
Have to write a Python app to communicate and fetch some data from a
I sent a text via GET method to decode html entities ( &#119; =
I have a list of System.DirectoryServices.ActiveDirectory.Domain objects gotten via this method. How do I
I have a method which is connecting to a database via Odbc. The stored
I'm extending a constructor class' functionality via the prototype method, but I'm having trouble
Our server got hacked via some SQL Injection method (now patched). All our PHP
I am trying to invoke method via webservice (SOAP) I have generated Web service

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.