I'm making a new web app using Rails, and was wondering, what's the difference between string
and text
? And when should each be used?
Ruby-on-rails – Difference between string and text in rails
ruby-on-rails
Related Question
- Ruby-on-rails – Rails: How to rename a database column in a Ruby on Rails migration
- Ruby-on-rails – Difference between attr_accessor and attr_accessible
- Ruby-on-rails – In Ruby on Rails, what’s the difference between DateTime, Timestamp, Time and Date
- Ruby-on-rails – raw vs. html_safe vs. h to unescape html
- Ruby-on-rails – Rails: How to run `rails generate scaffold` when the model already exists
- Ruby-on-rails – Is there documentation for the Rails column types
- Ruby-on-rails – @ variables in Ruby on Rails
- Ruby-on-rails – Getting error: Peer authentication failed for user “postgres”, when trying to get pgsql working with rails
Best Solution
The difference relies in how the symbol is converted into its respective column type in query language.
Reference:
When should each be used?
As a general rule of thumb, use
:string
for short text input (username, email, password, titles, etc.) and use:text
for longer expected input such as descriptions, comment content, etc.