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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -