2

i was wondering to set default value when we type command for model, i.e

rails g model admin user:string password:string

how i can set default value to user and pass "admin"

something like.

rails g model admin user:string default:"admin" password:string default:"admin"

Thanks

2 Answers 2

4

In your migration file, e.g.

t.decimal :bounties, :precision => 8, :scale => 2, :default => 0

OR set a callback

before_create :set_admin

def set_admin
  self.role = "admin"
end
Sign up to request clarification or add additional context in comments.

Comments

0

Hi one way is in migration file set default value by providing default hash and then migrate. or you can override new methods or if you want to create one admin user for application you can put into seed data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.