Sunday, March 23, 2014

Ruby on Rails models

We generate a rails model only once, when we want to create a new table in the database. After that we use migrations to make changes to our tables.

rails generate model User name:string email:string
bundle exec rake db:migrate

bundle exec rake db:rollback

rails console                     # Saves to DB
rails console --sandbox    # Will not save to DB

>> user = "Test One", email: "")     #Create in memory
>>          # Write to DB, returns true on success
>> user.updated_at
>> user2 = User.create(name: "Test two", email: "")  # Create and write to DB
>> user2.destroy

>> User.find(1)
>> User.find_by(email: "")

>> User.first
>> User.all

>> = ""
>> user.reload   # If you don't want to save your changes, and read details from DB

>> user.update_attributes(name: "Testing One", email: "") # write to DB
>> user.update_attribute(:name, "Tester One")

rake test:prepare

rails generate migration add_password_digest_to_users password_digest:string


vasudha dharani said...

Course contents
Database - basic - HTML / CSS - Caching & Routing - ROR-Architecture - HTML / CSS - More about Ruby -Ruby oops -ROR Validations & callbacks - XHTML/CSS - Ajax - Ruby oops - SVN -DB- Design - Employees to learn at their own pace and maintain control of learning “where, when and how” with boundless access 24/7by 21st Century Software Solutions. ---- Call Us +919000444287

Technologies said...

Thanks for information,we are providing more details visit our website.

Keen IT Technologies Pvt. Ltd. said...

Keen Technologies are the pioneers in the fields of providing SAP HCM Online Training center in all the method.We are the only institute in all over the world.For More Details visit