I recently did not find any tutorials for getting started on Ruby on Rails. The others are all download of e-books, and the existing notes are just the most basic.
Or some configuration tutorials.
I read some information in practical rails social networking sites Ruby on RALs and thought it was good. I 'd like to write it out and share it with you.
First, create a platform $ rails railscoders -- database = MySQL # specify the database as MySQL
Create a database before importing the database.
$ Mysql-u root-P
Password
> Create Database railscoders_development
Test whether the database can be migrated.
$ Rake DB: migrate
If no error message appears, congratulations! The migration is successful!
Explanations:
(1) here the database configuration file is in
../Railscoders/config/database. yml
You may need to modify the password of your database in this file !!!
(2) If you want to know more about rake
You can:
$ Rake-T
You can see what your rake command can do, haha
##########################
Paste my output
(In/home/hugewave/myprograme/rails/First)
Rake DB: abort_if_pending_migrations # raises an error if there are pending migrations
Rake DB: charset # retrieves the charset for the current environment's database
Rake DB: collation # retrieves the collation for the current environment's database
Rake DB: Create # create the database defined in config/database. yml for the current rails_env
Rake DB: Create: All # create all the local databases defined in config/database. yml
Rake DB: drop # drops the database for the current rails_env
Rake DB: Drop: All # drops all the local databases defined in config/database. yml
Rake DB: fixtures: Identify # search for a fixture given a label or ID.
Rake DB: fixtures: load # Load fixtures into the current environment's database.
Rake DB: migrate # migrate the database through scripts in dB/migrate and update dB/schema. rb by invoking DB: Schema: dump. target specific version with version = x. turn off output with verbose = false.
Rake DB: migrate: Down # runs the "down" for a given migration version.
Rake DB: migrate: redo # rollbacks the database one migration and re migrate up.
Rake DB: migrate: reset # resets your database using your migrations for the current environment
Rake DB: migrate: up # runs the "up" for a given migration version.
Rake DB: reset # drops and recreates the database from DB/Schema. RB for the current environment and loads the seeds.
Rake DB: rollback # rolls the schema back to the previous version.
Rake DB: Schema: dump # create a DB/Schema. RB file that can be portably used against any DB supported by Ar
Rake DB: Schema: load # load a schema. RB file into the database
Rake DB: seed # load the seed data from DB/seeds. Rb
Rake DB: Sessions: clear # Clear the sessions table
Rake DB: Sessions: Create # creates a sessions migration for use with activerecord: sessionstore
Rake DB: Setup # create the database, load the schema, and initialize with the seed data
Rake DB: Structure: dump # dump the database structure to a SQL File
Rake DB: Test: Clone # recreate the test database from the current environment's database schema
Rake DB: Test: clone_structure # recreate the test databases from the development structure
Rake DB: Test: load # recreate the test database from the current schema. Rb
Rake DB: Test: Prepare # Check for pending migrations and load the test Schema
Rake DB: Test: purge # Empty the Test Database
Rake DB: version # retrieves the current schema version number
Rake DOC: app # Build the rdoc HTML files
Rake DOC: clobber_app # Remove rdoc Products
Rake DOC: clobber_plugins # Remove plugin documentation
Rake DOC: clobber_rails # Remove rdoc Products
Rake DOC: Guides # generate rails guides
Rake DOC: plugins # generate documentation for all installed plugins
Rake DOC: rails # Build the rdoc HTML files
Rake DOC: reapp # force a rebuild of the rdoc files
Rake DOC: rerails # force a rebuild of the rdoc files
Rake gems # list the gems that this rails application depends on
Rake gems: build # build any native extensions for unpacked gems
Rake gems: Build: force # force the build of all gems
Rake gems: Install # installall required gems.
Rake gems: refresh_specs # regenerate gem specifications in correct format.
Rake gems: unpack # unpacks all required Gems into vendor/gems.
Rake gems: unpack: dependencies # unpacks all required gems and their dependencies into vendor/gems.
Rake log: clear # truncates all *. log files in log/to zero bytes
Rake middleware # prints out your rack middleware Stack
Rake notes # enumerate all annotations
Rake notes: Custom # enumerate a custom annotation, specify with annotation = wtfhax
Rake notes: fixme # enumerate all fixme annotations
Rake notes: optimize # enumerate all optimize annotations
Rake notes: Todo # enumerate all todo annotations
Rake rails: Freeze: edge # Lock to latest edge rails, for a specific release use release = 1.2.0
Rake rails: Freeze: gems # Lock this application to the current gems (by unpacking them into vendor/rails)
Rake rails: Template # applies the template supplied by location =/path/to/template
Rake rails: unfreeze # unlock this application from freeze of gems or edge and return to a fluid use of system gems
Rake rails: Update # update both configs, scripts and public/javascripts from rails
Rake rails: Update: application_controller # rename application. RB to application_controller.rb
Rake rails: Update: configs # update config/boot. RB from your current rails install
Rake rails: Update: generate_dispatchers # generate dispatcher files in rails_root/Public
Rake rails: Update: javascripts # update your javascripts from your current rails install
Rake rails: Update: scripts # Add new scripts to the application script/directory
Rake routes # print out all defined routes in match order, with names.
Rake Secret # generate a crytographically secure secret key.
Rake stats # report code statistics (klocs, etc) from the application
Rake test # Run all unit, functional and integration tests
Rake test: benchmark # Run tests for benchmarkdb: Test: Prepare/benchmark the performance tests
Rake test: functionals # Run tests for functionalsdb: Test: Prepare/run the functional tests in test/functional
Rake test: Integration # Run tests for integrationdb: Test: Prepare/run the integration tests in test/Integration
Rake test: plugins # Run tests for pluginsenvironment/run the plugin tests in Vendor/plugins/*/**/test (or specify with plugin = Name)
Rake test: Profile # Run tests for profiledb: Test: Prepare/profile the performance tests
Rake test: Recent # Run tests for recentdb: Test: Prepare/test recent changes
Rake test: uncommitted # Run tests for uncommitteddb: Test: Prepare/test changes since last checkin (only subversion and git)
Rake test: Units # Run tests for unitsdb: Test: Prepare/run the unit tests in test/Unit
Rake time: zones: All # displays names of all time zones recognized by the rails timezone class, grouped by offset.
Rake time: zones: Local # displays names of time zones recognized by the rails timezone class with the same offset as the system local time
Rake time: zones: US # displays names of us time zones recognized by the rails timezone class, grouped by offset.
Rake TMP: cache: clear # clears all files and directories in TMP/Cache
Rake TMP: clear # Clear session, cache, and socket files from TMP/
Rake TMP: Create # creates TMP directories for sessions, cache, sockets, and PIDs
Rake TMP: PIDs: clear # clears all files in TMP/PIDs
Rake TMP: Sessions: clear # clears all files in TMP/sessions
Rake TMP: sockets: clear # clears all files in TMP/sockets
##########################
Here, we will skip the page layout and CSS configuration, which is a large part of content, and I still don't know much about it.
Create a page model for me to import our database content
$ Ruby script/generate model page
After generating the model, let's change our configuration file.
../Railscoder/DB/migrate/20100326071901_create_pages.rb
Note that your file name may not be this, but the path is this. Haha, it seems that only this file is available now.
Let's take a look. You will see two definitions.
Def self. Up
Def self. Down
Change the content of this file to the following:
Class createpages <activerecord: Migration
Def self. Up
Create_table: pages do | T |
T. Column: title,: String
T. Column: permalink,: String
T. Column: body,: Text
T. Column: created_at,: datetime
T. Column: updated_at,: datetime
End
End
Def self. Down
Drop_table: pages
End
End
Maybe you don't quite understand this yet. Let's change the self. Up Method to this:
Def self. Up
Create_table: pages do | T |
T. Column: title,: String
T. Column: permalink,: String
T. Column: body,: Text
T. Column: created_at,: datetime
T. Column: updated_at,: datetime
End
Page. Create (: Title => "railscoders home ",
: Permalink => "Welcome-page ",
: Body => "Welcome to railscoders ")
End
In this way, you probably understand it.
Is to create a table, including what?
It includes title, permalink, body, create_at, update_at.
In fact, if you enter the database, a similar operation is:
> Create Table pages (
& Gt; Title varchar (200 ),
> Permalink varchar (200 ),
> Body varchar (200 ),
> Create_at time,
> Update_at time );
So you should understand it. Haha, it turns out that it is so simple to import data using Ruby.
Don't be too happy. You haven't imported it yet! How to get in, write a command:
$ Rake DB: migrate
Output information, it will tell you the success, haha
If you don't believe it, you can check it out.
Mysql> Use railscoders_development;
Mysql> select * from pages;
Have you seen the imported information in that file? haha!
Now, the data migration is over.
##########################
Finally, paste my Ruby on RALs Configuration
Ruby version |
1.8.7 i486-linux) |
Rubygems version |
1.3.5 |
Rack version |
1.0 |
Rails version |
2.3.5 |
Active record version |
2.3.5 |
Active resource version |
2.3.5 |
Action Mailer version |
2.3.5 |
Active support version |
2.3.5 |
Application Root |
/Home/hugewave/myprograme/rails/first |
Environment |
Development |
Database Adapter |
Sqlite3 |
Database schema version |
0 |
##########################