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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:30:07+00:00 2026-05-26T23:30:07+00:00

I have a model, Domain , which has a text field, names . >

  • 0

I have a model, Domain, which has a text field, names.

> rails g model Domain names:text
  invoke  active_record
  create    db/migrate/20111117233221_create_domains.rb
  create    app/models/domain.rb
> rake db:migrate
==  CreateDomains: migrating ==================================================
-- create_table(:domains)
   -> 0.0015s
==  CreateDomains: migrated (0.0066s) =========================================

I set this field as serialized into an array in the model.

# app/models/domain.rb
class Domain < ActiveRecord::Base
  serialize :names, Array
end

Create the ActiveAdmin resource for this model

> rails g active_admin:resource Domain
    create  app/admin/domains.rb

then, in the app/admin/domains.rb, I setup the various blocks to handle the serialized field as such

# app/admin/domains.rb
ActiveAdmin.register Domain do

  index do
    id_column
    column :names do |domain|
      "#{domain.names.join( ", " ) unless domain.names.nil?}"
    end
    default_actions
  end

  show do |domain|
    attributes_table do
      row :names do
        "#{domain.names.join( ", " ) unless domain.names.nil?}"
      end
    end
  end

  form do |f|
    f.inputs "Domain" do
      f.input :names
    end
    f.buttons
  end

  # before we save, take the param[:domain][:name] parameter,
  # split and save it to our array
  before_save do |domain|
    domain.names = params[:domain][:names].split(",") unless params[:domain].nil? or params[:domain][:names].nil?
  end
end

Nearly everything works great — my names are displayed as comma separated in the index and show views. When I update a record with my names field set to “a,b,c”, the before_save works to turn that into an array that is then saved via the ActiveRecord serialize.

What I can not solve is how to make the edit form put in a comma-separated list into the text field. I tried using a partial and using formtastic syntax directly as well as trying to make it work via the active_admin DLS syntax. Does anyone know how to make this work?

Specifically, if I have the following array saved in my domain.names field:

# array of names saved in the domain active_record
domain.names = ["a", "b", "c"]

how to change:

      form do |f|
        f.inputs "Domain" do
          f.input :names
        end
        f.buttons
      end

so that when the edit form is loaded, in the text field instead of seeing abc, you see a,b,c.

  • 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-26T23:30:08+00:00Added an answer on May 26, 2026 at 11:30 pm

    Here is a summary of how I handled this situation. I added an accessor to the model which can turn the Array into a string joined by a linefeed and split it back to an Array.

    # app/models/domain.rb
    class Domain < ActiveRecord::Base
      serialize       :names, Array
      attr_accessor   :names_raw
    
      def names_raw
        self.names.join("\n") unless self.names.nil?
      end
    
      def names_raw=(values)
        self.names = []
        self.names=values.split("\n")
      end
    end
    

    then, in my admin resource for domain, instead of using the :names field, I used the :names_raw field. setting this value would save the names Array with the new values.

    # app/admin/domains.rb
    form do |f|
      f.inputs "Domain" do
        f.input :names_raw, :as => :text
      end
      f.buttons
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
I have a domain model object which has properties of type System.DateTimeOffset. I'm using
I have an application A with a domain-model which is mapped to a database
I have an OrderForm domain class, which has property subclasses, something like: interface IOrderForm
I have a domain model that features a number of 'elements', pieces of text
I have a domain object which has a collection of primitive values, which represent
I'm working on a project which has a rich domain-model. Some of my classes
I have my domain model with several NewsType's which are subclasses of NewsItem as
I have a strong typed view model and a MetaData partial class which has
We have our domain model declared in rusty old hbm files, we wish to

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.