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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:48:43+00:00 2026-05-24T15:48:43+00:00

I have been looking at the ruby-docs but have not been able to make

  • 0

I have been looking at the ruby-docs but have not been able to make sense of them. I have an application that generates a table and stores files in each cell, a user can add another file by clicking on the last box which says “Add file”, but I can’t figure out how to do this in ruby.

In PHP I would do something like this; if it helps anyone get an idea:

for($i = 0; $i <= $file_array.size; $i++){
  if($i%3=0){
   html .= "</tr><tr>"
  }
  if($i == $array.size){
   //Prevents out of bounds error
   html .= "<td><a href=\"...\">New File Link</a></td>"
  }
 else{
  //We are not out-of-bounds; continue.
  html .= "<td><a href=\"$file_array[$i]\">File Link</a></td>"
 }
}

In ruby I have

 object.files.each_with_index |attachment, i|

but, I don’t know if that is what I want to use; I can’t figure out how to use it.

Update: I forgot to put table cells in the code.

  • 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-24T15:48:43+00:00Added an answer on May 24, 2026 at 3:48 pm

    Ruby’s each and each_with_index are kind of like PHP’s foreach loop. The variable attachment will be the element of the array:

    html = ""
    object.files.each_with_index do |attachment, i|
      html << "</tr><tr>" if i % 3 == 0
      html << "<a href=\"#{attachment}\">File Link</a>"
    end
    html << "<a href=\"...\">New File Link</a>"
    

    And don’t forget to sanitize your strings!

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

Sidebar

Related Questions

I am an experienced PHP programmer, but I have been looking into Ruby lately,
I have been looking for a fully functional WSDL client generator for ruby. I
I have been looking at ways to program a UI in ruby here, on
Have been looking at the MVC storefront and see that IQueryable is returned from
I've been looking to read some ruby code(specifically Rails) but I don't want to
I have been looking into Ruby and find its keywords until and unless very
I have been trying to install the Ruby PG gem, but kept getting the
Have been working in Ruby for a while, but usually in the context of
I have started learning ruby and i have been looking at ruby on rails.Is
I am using Rails 3.0.9. (With ruby 1.9.3) I have been looking into some

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.