[ruby]ruby on rails学习笔记1
准备:
ruby(windows): http://rubyforge.org/frs/?group_id=167
gem: http://rubyforge.org/frs/?group_id=126
gem install rails
创建应用项目:
rails new blog
配置数据库:
sqlite3:
development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000
mysq1:
development: adapter: mysql2 encoding: utf8 database: blog_development pool: 5 username: root password: socket: /tmp/mysql.sock
postgresql:
development: adapter: postgresql encoding: unicode database: blog_development pool: 5 username: blog password:
创建数据库:
rake db:create
运行web server:
rails server
生成一个控制器和方法
rails generate controller home index # home为控制器 index为方法
生成的代码
app/controllers/home_comtroller.rb
class HomeController < ApplicationController def index end end
删除 public/index.html
修改路由:
config/routes.rb
Blog::Application.routes.draw do #... # You can have the root of your site routed with "root" # just remember to delete public/index.html. root :to => "home#index"
think in coding