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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:00:55+00:00 2026-06-05T13:00:55+00:00

In writing a Rails app there are several places where string table column widths

  • 0

In writing a Rails app there are several places where string table column widths are needed: validations, RSpec testing, input forms, etc. It seems worthwhile to set the length limit on strings in the DB also.

At present I’ve set a LENGTHS hash in the model so I can access the lengths in other places and keep the code DRY in this respect. If I set the length limits in the DB, is it possible to read the values from there (or initialize the LENGTHS hash with them) to make the code even more DRY? That is, what is the code to read a string length limit of a database column in the model so I can use it?

  • 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-05T13:00:57+00:00Added an answer on June 5, 2026 at 1:00 pm

    You can access the columns method of your AR model.

    Model.columns.map(&:limit)
    Model.columns.map(&:name)
    Model.columns.map(&:null)
    Model.columns.map(&:sql_type)
    ...
    

    So you can use this method to construct your hash/array/whatever.
    I believe the length attibute you are talking about is limit in this notation.

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

Sidebar

Related Questions

i'm just writing my first app in rails and i wonder, if there is
As I've been writing test suites for a Rails app, I've noticed that there
I'm writing a rails app that has a model called 'User' and a model
I'm writing a Rails app which has the following jasmine spec: describe buttons, ->
I'm writing a Rails app that needs to store shape data representing the floor
I'm currently writing a Rails app, and hit a somewhat strange quirk. I have
I'm writing my first Rails app and I'm confused by a method call that
I am writing my first rails app. It needs to aggregate some data from
I'm writing a little Rails app & part of that is pulling in a
Hey--I'm writing a basic Rails app that uses the digg API. I'm trying 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.