Thursday, May 29, 2014

Notes - Rails Tutorial Chapter 7

== === eq? equal? 
http://stackoverflow.com/questions/7156955/whats-the-difference-between-equal-eql-and

Db:rest
Josh found:

http://stackoverflow.com/questions/10301794/difference-between-rake-dbmigrate-dbreset-and-dbschemaloadhttp://rake.rubyforge.org/

Rails comes equipped with three environments: test, development, and production. The default environment for the Rails console is development:

If you ever need to run a console in a different environment (to debug a test, for example), you can pass the environment as a parameter to the console script:

  $ rails console test

As with the console, development is the default environment for the local Rails server, but you can also run it in a different environment:

  $ rails server --environment production
If you view your app running in production, it won’t work without a production database, which we can create by running rake db:migrate in production:

  $ bundle exec rake db:migrate RAILS_ENV=production

REST!!!!!
POST, GET, PATCH, and DELETE
When following REST principles, resources are typically referenced using the resource name and a unique identifier.

show when Rails’ REST features are activated, GET requests are automatically handled by the show action.
HTTP requestURLActionNamed routePurpose
GET/usersindexusers_pathpage to list all users
GET/users/1showuser_path(user)page to show user
GET/users/newnewnew_user_pathpage to make a new user (signup)
POST/userscreateusers_pathcreate a new user
GET/users/1/editeditedit_user_path(user)page to edit user with id1
PATCH/users/1updateuser_path(user)update user
DELETE/users/1destroyuser_path(user)delete user
______________________________________________________________________________________________________________________________________________________________________

Here we’ve used params to retrieve the user id. When we make the appropriate request to the Users controller, params[:id] will be the user id 1, so the effect is the same as the find method
@user = User.find(params[:id])
User.find(1)
Technically, params[:id] is the string "1", but find is smart enough to convert this to an integer.

Factory Girl is a DSL for defining Active Record objects.

No comments:

Post a Comment