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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:04:49+00:00 2026-06-03T02:04:49+00:00

I am using Ruby on Rails v3.2.2 and I would like to protect a

  • 0

I am using Ruby on Rails v3.2.2 and I would like to “protect” a class/instance attribute so that a database table column value can be updated only one way. That is, for example, given I have two database tables:

table1
- full_name_column

table2
- name_column
- surname_column

and I manage the table1 so that the full_name_column is updated by using a callback stated in the related table2 class/model, I would like to make sure that it is possible to update the full_name_column value only through that callback.

In other words, I should ensure that the table2.full_name_column value is always

"#{table1.name_column} #{table1.surname_column}"

and that it can’t be another value. So, for example, if I try to “directly” update the table1.full_name_column, it should raise something like an error. Of course, that value must be readable.

Is it possible? What do you advice on handling this situation?


Reasons to this approach…

I want to use that approach because I am planning to perform database searches on table1 columns where the table1 contains other values related to a “profile”/”person” object… otherwise, probably, I must make some hack (maybe a complex hack) to direct those searches to the table2 so to look for "#{table1.name_column} #{table1.surname_column}" strings.

So, I think that a simple way is to denormalize data as explained above, but it requires to implement an “uncommon” way to handling that data.

BTW: An answer should be intend to “solve” related processes or to find a better approach to handle search functionalities in a better way.

  • 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-03T02:04:51+00:00Added an answer on June 3, 2026 at 2:04 am

    By replicating the data from table2 into table1 you’ve already de-normalized it. As with any de-normalization, you must be disciplined about maintaining sync. This means not updating things you’re not supposed to.

    Although you can wall off things with attr_accessible to prevent accidental assignment, the way Ruby works means there’s no way to guarantee that value will never be modified. If someone’s determined enough, they will find a way. This is where the discipline comes in.

    The best approach is to document that the column should not be modified directly, block mass-assignment with attr_accessible, and leave it at that. There’s no concept of a write-protected attribute, really, as far as I know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ruby on Rails and I would like to ensure that my
I am using Ruby on Rails 3.2.2 and in my controllers I would like
I am using Ruby on Rails 3.2.2 and rspec-rails-2.8.1. I would like to output
I'm using Authlogic with my Ruby on Rails App. I would like user to
I am using Ruby on Rails 3.1.0 and I would like to properly generate
I am using Ruby on Rails 3.1 and I would like to understand how
I am using Ruby on Rails 3.1 and I would like to know (for
I am using Ruby on Rails 3.0.9 and I would like to seed the
I am using Ruby on Rails 3.0.7 and I would like to document my
I am using Ruby on Rails 3.0.10 and I would like to build an

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.