- rails new 建立一個rails專案 rails new blog –skip-test-unit
- rails server|s 啟動伺服器
- rails console 開啟控制檯
-
rails generate controller StaticPages home help –no-test-framework 使用 –no-test-framework 選項禁用rspec框架生成測試程式碼。另外Rails會呼叫underscore方法把駝峰式的命名修改為蛇底式。例如上面的StatiPages的控制器對應的檔名為:static_pages_controller.rb,這只是一個約定,在命令列中也可以使用蛇底式。
在生成錯誤的時候可以使用
rails destroy [controller|model|view] [controller_name] [action] [action...]
來刪除指定的controller -
rake 用來編譯構建專案的一個工具,類似於unix下的make命令,可以用 rake -T 命令來檢視有什麼操作指令。
也可以檢視指定的命令的幫助,例如:rake -T db
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, … -
rails generate|g 生成器,可以以不同的指令生成不同形式的模板。
Rails:
- assets
- controller
- generator
- helper
- integration_test
- jbuilder
- mailer
- migration
- model
- resource
- scaffold
- scaffold_controller
- task
Coffee:
- coffee:assets
Jquery:
- jquery:install
Js:
- js:assets
TestUnit:
- test_unit:plugin
-
bundle install:我們使用 -without production 禁止安裝生產環境所需的 gem。這個選項會被記住,所以後續呼叫 Bundler 就不用再指定這個選項,直接執行 bundle install 就可以自動不安裝生產環境所需的 gem
安裝ckedit步驟:
-
加入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
Helper 標籤
- form_for
- link_to
- image_tag
- assets_tag
Gem命令
-
清除老版本的gem
gem cleanup -
刪除所有的已安裝的gem
for i in ‘gem list --no-versions’; do gem uninstall -aIx $i; done
軟體安裝
Mac 安裝libxml2
brew install libxml2 libxslt
brew link libxml2 libxslt
MySQL安裝:
sudo apt-get install mysql-server
修改密碼
mysqladmin -u賬號 -p老密碼 password 新密碼
設定編碼格式
create database ``test`` default character set utf8;
PostgreSQL安裝配置
http://dhq.me/mac-postgresql-install-usage
Heroku
刪除資料庫
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