实用工具--rails 命令、generator

1、rails 基本
rails new rails-bootstrap -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb

rails new User_Auth -d mysql

rails new $1 -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb

rails g model comment content:text commentable_id:integer commentable_type
rake db:migrate
rails g controller comments index new

rails new myapp -D postgres
cd myapp
rails generate scaffold user name:string age:integer
rake db:create
rake db:migrate

Rails app with mongoid devise haml
rails new webdb -m http://railswizard.org/77171980b8637239194c.rb -J -O -T

$ rails generate controller Noticias titulo
$ rails destroy controller Noticias titulo
$ rails generate model Noticia titulo:string
$ rails destroy model Noticia
 
$ rake db:migrate
$ rake db:rollback
$ rake db:migrate VERSION=0 #defaz todas as migrations, deixa o banco "limpo" 
$ rake db:migrate:reset #reseta todo o banco, perdendo todos os registros, e já executa novamente as todas as migrations




2、devise setup
rails g devise:install
rails g devise User
rails g devise:views
rake db:migrate 


3、Command to start delayed_job in production
RAILS_ENV=production script/delayed_job start


4、active_admin

install active_admin
bundle install
rails generate active_admin:install
rake db:migrate
rails s

generate active_admin ressources
rails generate active_admin:resource user
rails generate active_admin:resource product
rails generate active_admin:resource order



5、# Vagrant
vagrant halt
vagrant package --output ubuntu-12.04-LTS-RVM-Rails
vagrant box list
vagrant box add ubuntu-12.04-LTS-RVM-Rails ubuntu-12.04-LTS-RVM-Rails
vagrant box list

6、rvm rails


$ gem update --system# Get latest RubyGem
$ gem update ruby# Get latest Ruby
$ gem update rails# Get latest Rails

rvm use [email protected] --create# Set up rvm to use a different gemset (which in this case we will call Rails3.2)
 

gem install rails -v 3.2# install Rails 3.2 in that gemset
 

rvm gemset list# list the available rvm gemsets


HOW TO CREATE A GEMSET
# 在RVM环境下,必须已经安装了Ruby 1.9.2-p180,进入Ruby 1.9.2-p180的环境
rvm 1.9.2-p180 
# 在Ruby 1.9.2-p180的环境下,创建一个Ruby和Rails组合环境
rvm gemset create rails309 
# 进入1.9.2-p180@rails309组合环境
rvm 1.9.2-p180@rails309 
# 直接安装Rails,出现错误如下:
# "builder-2.1.2 has an invalid value for @cert_chain" 
# 更新gem
gem update --system 
# 调整gem版本到1.6.2
gem update --system 1.6.2 
# 在1.9.2-p180@rails309组合环境下,安装Rails版本3.0.9
gem install rails -v 3.0.9




7、git
git init
git add .
git ci -m "first commit"

8、vim
# 安装vim-rails
cd ~/.vim/bundle
git clone git://github.com/tpope/vim-rails.git
 
# 使用vim-rails实例
git clone git://github.com/cnruby/learn_rails.git
cd learn_rails/gon_demo
vim
:Rcontroller products<回车键>
:Rtree<回车键>
# 进一步使用方法请查看下面资料3。


# 安装Vimmer
gem install vimmer
 
# 使用Vimmer实例
vim install https://github.com/tpope/vim-rails

你可能感兴趣的:(Rails)