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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:49:30+00:00 2026-05-30T05:49:30+00:00

A quick warning: I am pretty new to Rails, and my knowledge is somewhat

  • 0

A quick warning: I am pretty new to Rails, and my knowledge is somewhat cookie-cutter-esque. I know how to do certain things, but I lack that vital understanding of why they always work.

I currently have a User model that has in it a bunch of information, like address, email, etc. In addition, it also has a hash called visible. The keys in that hash are each of the pieces of information, and the value is either true or false for whether the user wishes that information to be publicly visible. While I’m not sure if this is the best way to go, I can’t think of any other way other than making a whole ton of boolean variables for each bit of information. Finally, I serialize :visible for storage in the database

What I would like is in my edit view to have a checkbox beside each field of info that represents the visible attribute. After reading tons of other posts related to this topic and trying numerous variations of code, I always end up with some kind of an error. The code that looks most intuitively correct to me is as follows:

<%= form_for(@user, :id => "form-info-personal") do |f| %>
...
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.check_box :visible[:name] %>

But I get an error message saying that a Symbol cannot be parsed into an integer. I’m not sure where this parse is even trying to happen, unless its viewing :visible as an array and trying to use :name as an index.

I apologize in advance if this question is trivial/seemingly nonsensical/lacking vital information/etc. Any tips, suggestions, links, or what have you would be very appreciated, even if they’re along the lines of “you’re doing this fundamentally wrong, go back and do it this way”.

-Nick

  • 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-30T05:49:32+00:00Added an answer on May 30, 2026 at 5:49 am

    Rails 3.2 introduces a nice addition to ActiveRecord, which allows you to store arbitrary settings in a single field.

    class User < ActiveRecord::Base
      store :settings, accessors: [ :color, :homepage ]
    end
    
    u = User.new(color: 'black', homepage: '37signals.com')
    u.color                          # Accessor stored attribute
    u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor
    

    So, your code could look like this:

    # model
    class User < ActiveRecord::Base
      store :settings, accessors: [ :name_visible, :email_visible ]
    
    end
    
    # view
    <%= f.label :name %>
    <%= f.text_field :name %>
    <%= f.check_box :name_visible %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did a quick search but could not find anything about this. I guess all
Possible Duplicate: Rails primary key and object id Very quick question. My server is
I will confess I'm very new to Python and I don't really know what
Wrote the following in PowersHell as a quick iTunes demonstration: $iTunes = New-Object -ComObject
got a quick question for you (pretty much the title): is the book Cocoa
Quick Explanation One Silverlight (3.0) project with several XAML pages. I want to load
quick and very basic newbie question. If i have list of dictionaries looking like
Quick background: I'm programming in PHP, I have a domain model with a separate
Quick one. I'm using mod rewrite and have most replacements in place: empty space
Quick question. For some reason links referencing the home page contain an extra /web/guest/home

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.