如何简单快速的完成用户角色管理和权限控制(2)创建 Rails 程序
- UID
- 1066743
|
如何简单快速的完成用户角色管理和权限控制(2)创建 Rails 程序
创建 Rails 程序$rails new DeveloperWork
- 用 rails generate scaffold 命令创建一个新资源
$ rails generate scaffold paper name:text content:text category:text owner:text
$ rake routes | grep paper
清单1. rails 为 papers 分配的 routesshirleydembpeveloperWork shirley$ rake routes | grep paper
1
2
3
4
5
6
7
8
| papers GET /papers(.:format) papers#index
POST /papers(.:format) papers#create
new_paper GET /papers/new(.:format) papers#new
edit_paper GET /papers/:id/edit(.:format) papers#edit
paper GET /papers/:id(.:format) papers#show
PATCH /papers/:id(.:format) papers#update
PUT /papers/:id(.:format) papers#update
DELETE /papers/:id(.:format) papers#destroy
|
$ bin/rails db:migrate RAILS_ENV=development
编辑程序的 config/routes.rb,添加程序首页的 routes
清单2. routes.rb中的配置Rails.application.routes.draw do
resources :papers
# Details to see http://guides.rubyonrails.org/routing.html
1
| # get '/' => 'papers#index'
|
root 'papers#index'
end
- 在 Gemfile 中引入 twitter-bootstrap-rails
gem twitter-bootstrap-rails
$ bundle install
$ rails generate bootstrap:install
$ rails g bootstrap:layout
$ rails g bootstrap:themed papers
$rails server –h <hostIP> -p <port>
图1. 程序首页 |
|
|
|
|
|