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

  • Home
  • SEARCH
  • 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 9253313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:11:18+00:00 2026-06-18T11:11:18+00:00

This is a simple question yet I’m having a hard time finding an answer.

  • 0

This is a simple question yet I’m having a hard time finding an answer. I have a select field in my form and I want to build the options array depending on my query records count.

I’m getting my count like so in my controller:

@num_pages= Page.where(:site_id => @siteid).count

I want my options array to just be like {[“1”, 1], [“2”, 2], …} all the way up to @num_pages.

Now I KNOW I can just do a loop and build that array but I want to know if there is a more “rails” way to do it. So that my select code could still be as simple as this:

<%= select_tag(:nav_order, options_for_select(@num_pages)) %>

…without using loops and array pushes and what have you.

UPDATE

Thanks to the responses my code now works like this. I decided to keep the mapping in the view instead of the controller however.

<% options_array = (1..@page_count).to_a.collect{|p| ["#{p}", p]} %>  
<%= select_tag(:nav_order, options_for_select(options_array)) %>
  • 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-18T11:11:19+00:00Added an answer on June 18, 2026 at 11:11 am

    Build the array in the controller?

    num = Page.where(:site_id => @siteid).count
    @num_pages = (1..num).to_a.collect{|p| ["#{p}", p]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a simple question... yet I have spent some time poking around online
This is a very simple question yet I have little knowledge in Linux and
Okay this may be a simple question but I have yet to come with
I have a simple question yet it's not working out. See this html: <div
This question might appear very simple, but i haven't found an answer yet, so
A simple question and yet I can't find an answer for it. I have
Simple question, hard to find an answer: If I try to select a row
I have a rather interesting question that seems simple to answer, yet I have
This is a simple question yet I was unable to find any information at
i have this simple question please. I have this part of code which sets

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.