Rails Study

Rails Philosophy

  1. DRY – “Don’t Repeat Yourself” – suggests that writing the same code over and over again is a bad thing.
  2. Convention Over Configuration – means that Rails makes assumptions about what you want to do and how you’re going to do it, rather than requiring you to specify every little thing through endless configuration files.
  3. REST is the best pattern for web applications – organizing your application around resources and standard HTTP verbs is the fastest way to go.
    • Using resource identifiers such as URLs to represent resources.
    • Transferring representations of the state of that resource between system components.

Install Rails

  1. according to steps on offical website do
    1
    
    gem install rails; rails new rails-test; cd rails-test; rails server
    
  1. when running rails server i met such problem:
    1
    2
    3
    
    $ rails server
    /home/zheng/.rvm/gems/ruby-2.0.0-p0/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. 
    See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
    

This means i need a js engine, and i install the nodejs instead, and it's ok

  1. try to open localhost:3000, and you'll see welcome page

  2. Switch to MySQL instead of SQLite3:

    • the config file is in config/database.yml and change the "development" section like that
    • add gem 'mysql2' to Gemfile
    • run rake db:create to check is there any problem
      1
      2
      3
      4
      5
      6
      7
      8
      
      development:
          adapter: mysql2
          encoding: utf8
          database: rails-test
          pool: 5
          username: root
          password:
          socket: /var/run/mysqld/mysqld.sock
      

Remember the test section will also be set to mySQL