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

The Archive Base Latest Questions

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

I have two tables: groups and series. A serie has_many groups and a group

  • 0

I have two tables: groups and series. A serie has_many groups and a group belongs_to a serie.
I’m using Formstastic to automatically generate a <select> with all the series so the user will be able to select the serie related to the group being created.
But a serie belongs_to the table units, which has_many series. Since series have the same name, it will not possible for the user to know exactly which serie he’s choosing in the <select>, unless he knows to which unit a specific serie belongs to. For that I’d like every <option> to have the following format:

<option value="serie_id">serie.name – unit.name</option>

What I have until now (and working) is:

ActiveAdmin.register Group do

  form do |f|
    f.inputs "Group" do       
        f.input :serie
        f.input :name
    end                               
  f.actions                         
  end 
end

Any other suggestion on how to achieve my goal (specifying exactly the serie related to the unit) will be appreciated.

  • 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:48:04+00:00Added an answer on June 18, 2026 at 11:48 am

    Try the following:

    # in controller
    @custom_collection = Serie.all.map{ |s| ["#{s.name} - #{s.unit.name}", s.id]}
    
    # in view
    f.input :serie, collection: options_for_select(@custom_collection)
    

    This code assumes that a Serie always have a Unit associated. It will raise an error if not. Use the following if you want to show the unit name only if it exists:

    @custom_collection = Serie.all.map do |serie|
      composed_name = s.name
      composed_name += " - #{s.unit.name}" if s.unit.present?
      [composed_name, s.id]
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, users and groups . An user owns a group and
I am using two tables for maintaining Items-Groups relationship. I have items table which
I have two tables: groups and group_members . The groups table contains all the
I have two tables (groups and parties) in a many to many relationship using
I have the following two database tables. A group contains multiple members. Groups: Id
I have following two tables 'USERS' and 'GROUPS': USERS -id -name -groupid GROUP -id
I have the following two tables Groups Id (int) People Id (int) GroupId (int,
I have the following two tables in my mysql database. Table Name: groups id
I have the following two table: -Groups- Id Name -Members- Id GroupId (Group.Id is
Possible Duplicate: Retrieving the last record in each group I have two tables set

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.