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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:47:34+00:00 2026-05-30T16:47:34+00:00

I want to implement a feature where user can add new attributes to his

  • 0

I want to implement a feature where user can “add new attributes” to his profile. Here he should be able to create the label for the detail and the actual details like:

Education : Degree 

where Education is the label for the detail and Degree is the detail.

Apart from this, he should also have an option to decide whether this details should be made visible or hidden.

How can I implement this using a new model Profile with the association

User has_one Profile.

If I just had Label and Text for the new details, I could have tried hash, but since I would also have to get the details from the user on whether the user wants the detail to be made hidden or visible, I might require an extra field to store that value (true or false).So how can I implement that ?

I cannot create a has_many Profile user_id:integer name:string content:string visible:boolean since what I need is a has_one association.

I am really confused as to how I can get the whole thing implemented together.

Please suggest me how I can implement this and also how can I update the model each time a user creates a new detail without changing the schema of the db.

I am working on Rails 3.2.

  • 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-30T16:47:35+00:00Added an answer on May 30, 2026 at 4:47 pm

    Assuming you have a column named attributes of type text in your profile table

    class AddAttributesToProfile < ActiveRecord::Migration
      def self.up
        add_column :profiles, :attributes, :text
      end
    
      def self.down
        remove_column :profiles, :attributes
      end
    end
    

    Then you can use the serialize method in your model:

    class Profile < ActiveRecord::Base 
      serialize :attributes, Hash
    end
    

    This will allow you to write code like this:

    profile.attributes = { :education => ["Chef degree", true], :hobby => ["Cook", false] }
    profile.save
    

    The Hash will be serialized in YAML format.


    Edit: CRUD operations

    To add or modify the education:

    profile.attributes[:education] = ["Another title", true] # the boolean here represents the visibility
    

    To query for all the visible attributes:

    profile.attributes.each{|key, value| print "#{key.to_s.capitalize} : #{value.first}" if value.second}
    

    To delete the education:

    profile.attributes.delete :education
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a login page, it can easy implement using Ruby on
I want to implement chat feature in my android application,in this feature one user
I have an app in which i want to implement a feature where user
I want to implement a search feature in an iPhone app. Basically, the user
I want to implement an autocomplete feature with images in my website. I would
I want to implement an ISAPI filter like feature using HttpModule in IIS7 running
We want to implement a sitemap.xml feature in out CMS system. There is some
I m using Osmdroid to create an offline map Now, i want to implement
I have a drawing app in which I want to implement UNDO feature so
I am writing a WPF application, and one feature I want to implement is

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.