rails generate controller StaticPages home help --no-test-framework 使用 --no-test-framework 選項禁用rspec框架生成測試代碼。另外Rails會調用underscore方法把駝峯式的命名修改成蛇底式。例如上面的StatiPages的控制器對應的文件名爲:static_pages_controller.rb,這只是一個約定,在命令行中也可使用蛇底式。css
在生成錯誤的時候可使用 rails destroy [controller|model|view] [controller_name] [action] [action...]
來刪除指定的controllerhtml
rake 用來編譯構建項目的一個工具,相似於unix下的make命令,能夠用 rake -T 命令來查看有什麼操做指令。mysql
也能夠查看指定的命令的幫助,例如:rake -T dbjquery
rake about # List versions of all Rails frameworks and the...
rake assets:clean # Remove old compiled assets
rake assets:clobber # Remove compiled assets
rake assets:environment # Load asset compile environment
rake assets:precompile # Compile all the assets named in config.assets...
rake db:create # Create the database from DATABASE_URL or conf...
rake db:drop # Drops the database using DATABASE_URL or the ...
rake db:fixtures:load # Load fixtures into the current environment's ...
rake db:migrate # Migrate the database (options: VERSION=x, VER...
rake db:migrate:status # Display status of migrations
rake db:rollback # Rolls the schema back to the previous version...
rake db:schema:cache:clear # Clear a db/schema_cache.dump file
rake db:schema:cache:dump # Create a db/schema_cache.dump file
rake db:schema:dump # Create a db/schema.rb file that can be portab...
rake db:schema:load # Load a schema.rb file into the database
rake db:seed # Load the seed data from db/seeds.rb
rake db:setup # Create the database, load the schema, and ini...
rake db:structure:dump # Dump the database structure to db/structure.sql
rake db:version # Retrieves the current schema version number
rake doc:app # Generate docs for the app -- also available d...
rake log:clear # Truncates all *.log files in log/ to zero byt...
rake middleware # Prints out your Rack middleware stack
rake notes # Enumerate all annotations (use notes:optimize...
rake notes:custom # Enumerate a custom annotation, specify with A...
rake rails:template # Applies the template supplied by LOCATION=(/p...
rake rails:update # Update configs and some other initially gener...
rake routes # Print out all defined routes in match order, ...
rake secret # Generate a cryptographically secure secret ke...
rake stats # Report code statistics (KLOCs, etc) from the ...
rake test # Runs test:units, test:functionals, test:integ...
rake test:all # Run tests quickly by merging all types and no...
rake test:all:db # Run tests quickly, but also reset db
rake test:recent # Run tests for {:recent=>["test:deprecated", "...
rake test:uncommitted # Run tests for {:uncommitted=>["test:deprecate...
rake time:zones:all # Displays all time zones, also available: time...
rake tmp:clear # Clear session, cache, and socket files from t...
rake tmp:create # Creates tmp directories for sessions, cache, ...git
rails generate|g 生成器,能夠以不一樣的指令生成不一樣形式的模板。github
Rails:sql
Coffee:數據庫
Jquery:服務器
Js:restful
TestUnit:
bundle install:咱們使用 -without production 禁止安裝生產環境所需的 gem。這個選項會被記住,因此後續調用 Bundler 就不用再指定這個選項,直接運行 bundle install 就能夠自動不安裝生產環境所需的 gem
加入gem
gem 'ckeditor'
gem 'paperclip'
生成文件rails generate ckeditor:install --orm=active_record --backend=paperclip
配置 model 環境,打開 application.rb 加入下面config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
在 routes 裏面增長 路由mount Ckeditor::Engine => "/ckeditor"
打開application.js 加入//= require ckeditor/init
更多內容請查看:https://github.com/galetahub/ckeditor
默認狀況下Rails erb輸出會轉義html標籤,如何在rails中不讓html標籤轉義?
答:使用raw 或者 html_safe
如何過濾掉html、css、js標籤?
答案:能夠是用SanitizeHelper,有以下方法:sanitize、strip_css、strip_links、strip_tags
經常使用 rake 命令
rake assets:precompile 編譯靜態資源文件
rake routes 列出全部的restful route
rake stats 查看當前工程狀況
rake secret 生成session 加密指紋
Rails debug
增長下面的代碼gem debugger
rails s --debugger
而後在須要debug的地方加上 debugger 就能夠了。
查看資源路徑Rails.application.config.assets.paths
清除老版本的gem
gem cleanup
刪除全部的已安裝的gemfor i in ‘gem list --no-versions’; do gem uninstall -aIx $i; done
brew install libxml2 libxslt brew link libxml2 libxslt
sudo apt-get install mysql-server
mysqladmin -u帳號 -p老密碼 password 新密碼
create database ``test`` default character set utf8;
http://dhq.me/mac-postgresql-install-usage
刪除數據庫
heroku pg:reset
第一章 http://www.tuicool.com/articles/3uyAny
第二章 http://www.tuicool.com/articles/Y363Erf
第三章 http://www.tuicool.com/articles/MnMf2i
第四章 http://www.tuicool.com/articles/j2Erye
第五章 http://www.tuicool.com/articles/u6FRBr7
第六章 http://www.tuicool.com/articles/6j67je