Rails 101 第一遍
建立一个新 Rails 项目
rails new rails101 cd rails101 git init git add . git commit -m "Initial Commit"
引入框架 Bootstrap
git checkout -b ch01 atom . gem 'bootstrap-sass' bundle install mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss @import "bootstrap-sprockets"; @import "bootstrap"; git add . git commit -m "add bootstrap to project"
mkdir app/views/common touch app/views/common/_navbar.html.erb touch app/views/common/_footer.html.erb gem 'sqlite3', '~> 1.3.13' bundle install rails g controller welcome touch app/views/welcome/index.html.erb root 'welcome#index' git add . git commit -m "add bootstrap html" rails s
app/assets/javascripts/application.js touch app/views/common/_flashes.html.erb touch app/helpers/flashes_helper.rb application.html.erb git add . git commit -m "add bootstrap flash function" app/controllers/welcome_controller.rb
建立讨论群的架构
git checkout -b ch02 rails g model group title:string description:text rake db:migrate rails g controller groups app/controllers/groups_controller.rb touch app/views/groups/index.html.erb config/routes.rb rails console Group.create(title: "Board 1", description: "Board 1 body") Group.create(title: "Board 2", description: "Board 2 body") exit git add . git commit -m "create groups index"
config/routes.rb git add . git commit -m "replace root with groups#index"
增
git checkout -b ch03 app/controllers/groups_controller.rb touch app/views/groups/new.html.erb git add . git commit -m "implement groups#new" app/controllers/groups_controller.rb git add . git commit -m "implement groups#create"
查
app/controllers/groups_controller.rb touch app/views/groups/show.html.erb git add . git commit -m "implement groups#show"
改
app/controllers/groups_controller.rb touch app/views/groups/edit.html.erb git add . git commit -m "implement groups#edit " app/controllers/groups_controller.rb git add . git commit -m "implement groups#update "
删
app/controllers/groups_controller.rb git add . git commit -m "implement groups#destroy "
限制标题为空新增
app/models/group.rb app/controllers/groups_controller.rb app/views/groups/new.html.erb git add . git commit -m "add validation to title" app/controllers/groups_controller.rb app/views/groups/edit.html.erb git add . git commit -m "add validation to title apply to edit/update"
共用“表单”
touch app/views/groups/_form.html.erb app/views/groups/new.html.erb app/views/groups/edit.html.erb git add . git commit -m "move form to partial"
将表单换为 Bootstrap 提供的版型
app/views/groups/_form.html.erb git add . git commit -m "style form with bootstrap" gem 'simple_form' bundle install rails generate simple_form:install --bootstrap rails s app/views/groups/_form.html.erb git add . git commit -m "replace form with simple_form bootstrap template"
安装登录系统
git checkout -b ch04 gem 'devise' bundle install rails g devise:install rails g devise user rake db:migrate rails server app/controllers/groups_controller.rb git add . git commit -m "install devise"
注册登录退出
app/views/common/_navbar.html.erb app/assets/javascripts/application.js git add . git commit -m "user can login/logout/signup"
关联群组和使用者
rails g migration add_user_id_to_group db/migrate/一串数字_add_user_id_to_group.rb rake db:migrate app/models/user.rb app/models/group.rb app/controllers/groups_controller.rb git add . git commit -m "add user_id to group" app/views/groups/index.html.erb rails console Group.delete_all exit git add . git commit -m "show group's creator info "
编辑删除权限
app/views/groups/index.html.erb git add . git commit -m "people can't see edit button unless he is group owner" app/controllers/groups_controller.rb git add . git commit -m "check owner permission when access edit/update/destroy" app/controllers/groups_controller.rb git add . git commit -m "use before_action to find_group_and_check_permission" app/views/groups/show.html.erb git add . git commit -m "add permission check on show page"
添加写文章按钮
git checkout -b ch05 rails g model post content:text group_id:integer user_id:integer rake db:migrate app/models/group.rb app/models/user.rb app/models/post.rb git add . git commit -m "add post and hook group/user relation" rails g controller posts config/routes.rb rake routes git add . git commit -m "add posts nested route" app/views/groups/show.html.erb git add . git commit -m "add post button"
实现文章页面
app/controllers/posts_controller.rb touch app/views/posts/new.html.erb app/controllers/groups_controller.rb app/views/groups/show.html.erb app/models/post.rb git add . git commit -m "implement post create function"
文章倒序
app/controllers/groups_controller.rb git add . git commit -m "add order by created_at to group's post" app/models/post.rb app/controllers/groups_controller.rb git add . git commit -m "using scope to write order by created_at to group's post"
文章分页
gem 'will_paginate' bundle install rails server app/controllers/groups_controller.rb app/views/groups/show.html.erb git add . git commit -m "implement posts pagination with will_paginate"
第六章
git checkout -b ch06 rails g model group_relationship group_id:integer user_id:integer rake db:migrate app/models/user.rb app/models/group_relationship.rb app/models/group.rb rails console git add . git commit -m "implement group relation"
是否是群组成员
app/models/user.rb rails console exit app/views/groups/show.html.erb git add . git commit -m "implement is_member_of?(group)"
加入或退出群组
app/models/user.rb rails console exit git add . git commit -m "join or quit group"
app/controllers/groups_controller.rb config/routes.rb app/views/groups/show.html.erb git add . git commit -m "join & quit group action"
创建者自动成为组成员
app/controllers/groups_controller.rb git add . git commit -m "when created a group, join it automatically"
我的小组
git checkout -b ch07 rails g controller account/groups config/routes.rb app/views/common/_navbar.html.erb account/groups_controller.rb touch app/views/account/groups/index.html.erb git add . git commit -m "implement my groups"
我的文章
rails g controller account/posts account/posts_controller.rb config/routes.rb app/views/common/_navbar.html.erb touch app/views/account/posts/index.html.erb git add . git commit -m "implement my posts"
额外作业
posted on 2019-04-30 16:15 GoBackHome 阅读(155) 评论(0) 编辑 收藏 举报