Einstieg in Rails

Angelegt von hannes Tue, 23 Feb 2010 13:18:00 GMT

QUICK START:

> CREATE APP > config/database.yml > CREATE DB > GENERATE SCAFFOLD > MIGRATE DB > START SERVER


APP/MODELS:

Model1 > Migration1a > DB (schema)
Model1 > Migration1b > DB (schema)
Model2 > Migration2a > DB (schema)


- models can have validations (on error message stored in errors) and callbacks (together with database operation in execution queue)
- observers for external callbacks

- models validation aren't performed on every operation

- environment for global app changes (routes, observers)

GENRERATE MODEL:
$ script/generate model  : :

GENERATE SCAFFOLD (model, controller, views):
$ script/generate scaffold  : :


APP/CONROLLERS:

- have params, request as params
- have magic url/path methods

- params[:]
- session[:]
- cookies[:]
- redirect_to_url

- validate_presence_of :

GENERATE CONTROLLER:
$ script/generate controller   


APP/VIEWS:

- flash[:]


APP:

CREATE APP:
$ rails 

SCHOW RAKE TASKS:
- rake --tasks


START SERVER:
$ script/server -e development | test | production
$ script/server --debugger (Stops execution when 'debugger' is called in controller in development Mode and allows live debugging)


SHOW LOG:
$ tail -f log/development.log

OPEN CONSOLE:
$ script/console

DEBUG (call breakpoint('') from code and interactive console is started when reached):
$ script/breakpointer



DB:

CREATE DB:
$ rake db:create

LOAD SCHEMA TO EXISTING DB:
$ rake db:schema:load

MAKE COPY OF SCHEMA:
$ rake db:schema:dump

LOAD DATA TO DB:
$ rake db:fixtures:load

RESET DB:
$ rake db:reset

MIGRATE DB (calls up method of new migrations and makes changes to db):
$ rake db:migrate

ROLLBACK DB (calls down method of the last x migrations and undos changes from db):
$ rake db:rollback STEP=

CREATE MIGRATION (AddFieldNameToModelName):
$ script/generate migration  :
$ script/generate migration  :
$ script/generate migration  : :



CONFIG:

SHOW ROUTES:
$ rake routes


TOOLS:

- extend core behavior
- like rails apps
- configured in init.rb


VENDOR/PLUGINS:

INSTALL PLUGIN:
$ script/plugin install 


TEST:

- fixtures hold testata for models in YAML format
- unit test for models
- functional test for controllers



RECREATES TEST DB ENVIRONMENT DB SCHEMA:
$ rake db:test:clone

RECREATES TEST DB FROM SCHEMA:
$ rake db:test:load 

CLONE PRODUCTION TO TEST DATAVASE:
$ rake clone_structure_to_test

REBUILD TEST DB FROM DEVELOPMENT DB:
$ rake db:test:prepare



RUN TEST SCRIPT:
$ ruby test/unit/_test.rb

RUN ALL TESTSCRIPTS:
$ rake test_units
$ rake test_functional

SHOW STATS:
$ rake stats


Trackbacks

Verwenden Sie den folgenden Link zur Rückverlinkung von Ihrer eigenen Seite:
http://praktikanten.brueckenschlaeger.org/trackbacks?article_id=36

Leave a comment

Comments