Ruby on Rails 实战

1.创建项目:

rails new projName --skip-bundle

2.启动服务器

cd 到项目根目录

rails server
  1. 新建controller

    rails generate controller controllerName index

4.更改首页展示路径:

Rails.application.routes.draw do
  root :to => 'home#index'

  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.htm

end

这句话是让展示的路径:

root :to => 'home#index'  # home controller 的index action

基本工作流 ruby on rails

  1. 使用Rails 命令去创建基本的application框架
  2. 创建一个database 去 存储你的data
  3. 配置application去知道你的database位于哪儿,和login credentials
  4. 创建Rails Active Records(Models) ,你将会使用它们与cntrollers去交流。
  5. 生成迁移,使得创建和维护database的表和数据更加方便
  6. 写一个controller 代码去put a life 在你的application 中
  7. 写views 去展示你的数据通过用户界面

注意:
resources :posts , 不能 resources: posts,注意格式

注意:
$ rake db:migrate 作用是?

rake db:migrate                      # Migrate the database through scripts in db/migrate.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容