sql - Rails/PostgreSQL: Adding character limit to text -
i want implement character limit data value on postgresql database ruby on rails application. database table looks this:
create_table "applications", force: :cascade |t| t.string "name" t.string "gender" t.date "date_of_birth" t.string "gpa" t.text "essay" t.datetime "created_at", null: false t.datetime "updated_at", null: false end
i want change "essay" allows 10000 characters. limited understanding of postgresql, text unlimited default whereas string 255 characters or less. thought implementing javascript conditional not let user hit submission button in client if text on 1,000 characters, of course tech savvy user change that. optimal way this?
use rails model validations - validates_length_of.
on rails end can add in application.rb
file
validates_length_of :essay, :maximum => 1000
this ensure max size not exceded. keep javascript validation, since helpful users except malicious once.
also recommend change table name applications
. can confused
Comments
Post a Comment