[ROR] ruby on rails 命令學習

來源:互聯網
上載者:User

1.1 link_to

一般形式:

link_to "xxxx",{hash},{hash}
第一個是連結文字,第二個hash和url_for的一樣,第三個hash是使用者自己在<a>中添加的標籤,比如:

<%= link_to "Issues", {:controller => "issue", :action => "index"}, {:title => "Issues"} %>

link_to_unless_current 自動識別當前連結, 如果當前url和連結一樣, 就只產生文本

 

事實上,html元素的屬性都可以通過這樣的方式來設定。比如添加一個click事件處理:

<%= link_to "Issues", {:controller => "issue", :action => "index"}, {:onclick => "alert(1)"} %> 

注意:link_to 的第二個參數,必須是以 map 的形式給出。link_to 是 rails 預設提供的工具方法,它還有一個過載的方法:<%= link_to "Issues", "index", {:onclick => "alert(1)"} %> 

顯示結果:"/xxxxx/controller/index?onclick=alert(1)"

 

所以如果第二個參數以字串的形式給出,此時其後的參數,就變為queryString了。

那麼如何?又增加 click 事件處理,又增加url參數呢,很簡單, 如下:

<%= link_to "Issues", {:controller => "issue", :action => "index", :param=value}, :onclick => "alert(1)" %>

 

結果為:

<a href="/issue/index?param=value" script_onclick="alert(1)">Issues</a>

1.2 rake
 rake db:fixtures:load
  # 載入fixtures到當前環境的資料庫
  # 載入指定的fixtures使用FIXTURES=x,y
 rake db:migrate
 # 遷移資料庫通過在db/migrate目錄下的指令碼.可以指定版本號碼通過VERSION=x
 rake db:schema:dump
 # 建立一個db/schema.rb檔案,通過AR能過夠支援任何資料庫去使用
 rake db:schema:load
 # 再入一個schema.rb檔案進資料庫
 rake db:sessions:clear
 # 清空sessions表
 rake db:sessions:create
 # 用CGI::Session::ActiveRecordStore建立一個sessions表為使用者
 rake db:structure:dump
 # 匯出資料庫結構為一個SQL檔案
 rake db:test:clone
 # 重新建立一個測試資料庫從當前環境資料庫中
 rake db:test:clone_structure
 # 重新建立測試資料庫從開發模式資料庫
 rake db:test:prepare
 # 準備測試資料庫並在入schema
 rake db:test:purge
 # 清空測試資料庫
 rake doc:app
 # 建立HTML檔案的API Documentation
 rake doc:clobber_app
 # 刪除Documentation
 rake doc:clobber_plugins
 # 刪除 plugin Documentation
 rake doc:clobber_rails
 # 刪除Documentation
 rake doc:plugins
 # 產生Documation為所有安裝的plugins
 rake doc:rails
 # 建立HTML檔案的API Documentation
 rake doc:reapp
 # 強制重新建立HTML檔案的API Documentation
 rake doc:rerails
 # 強制重新建立HTML檔案的API Documentation
 rake log:clear
 # 清空目錄log/下的所有記錄檔
 rake rails:freeze:edge
 # Lock this application to latest Edge Rails. Lock a specific revision with REVISION=X
 rake rails:freeze:gems
 # Lock this application to the current gems (by unpacking them into vendor/rails)
 rake rails:unfreeze
 # Unlock this application from freeze of gems or edge and return to a fluid use of system gems
 rake rails:update
 # Update both scripts and public/javascripts from Rails
 rake rails:update:javascripts
 # Update your javascripts from your current rails install
 rake rails:update:scripts
 # Add new scripts to the application script/ directory
 rake stats
 # Report code statistics (KLOCs, etc) from the application
 rake test
 # Test all units and functionals
 rake test:functionals
  # Run tests for functionalsdb:test:prepare
 rake test:integration
 # Run tests for integrationdb:test:prepare
 rake test:plugins
 # Run tests for pluginsenvironment
 rake test:recent
 # Run tests for recentdb:test:prepare
 rake test:uncommitted
 # Run tests for uncommitteddb:test:prepare
 rake test:units
 # Run tests for unitsdb:test:prepare
 rake tmp:cache:clear
 # 清空tmp/cache目錄下的所有檔案
 rake tmp:clear
 # 清空session, cache, 和socket檔案從tmp/目錄
 rake tmp:create
 # 為sessions, cache, and sockets建立tmp/目錄
 rake tmp:sessions:clear
 # 清空所有在tmp/sessions目錄下的檔案
 rake tmp:sockets:clear
 # 清空所有在tmp/sessions 目錄下的ruby_sess.* 檔案
 
1.3 Scripts
 script/about
 # 輸出當前環境資訊
 script/breakpointer
 # 啟動斷點server
 script/console
 # 啟動交換式的Rails控制台
 script/destroy
 # 刪除通過generators建立的檔案
 script/generate
 # -> generators
 script/plugin
 # -> Plugins
 script/runner
 # 執行一個任務在rails上下文中
 script/server
 # 啟動開發模式伺服器http://localhost:3000
 //以下幾個不知道怎麼去使用
 script/performance/profiler
 script/performance/benchmarker
 script/process/reaper
 script/process/spawner
 
1.4 Generators
 ruby script/generate model ModelName
 ruby script/generate controller ListController show edit
 ruby script/generate scaffold ModelName ControllerName
 ruby script/generate migration AddNewTable
 ruby script/generate plugin PluginName
 ruby script/generate mailer Notification lost_password signup
 ruby script/generate web_service ServiceName api_one api_two
 ruby script/generate integration_test TestName
 ruby script/generate session_migration
 可選項:
 -p, --pretend Run but do not make any changes.
 -f, --force Overwrite files that already exist.
 -s, --skip Skip files that already exist.
 -q, --quiet Suppress normal output.
 -t, --backtrace Debugging: show backtrace on errors.
 -h, --help Show this help message.
 -c, --svn Modify files with subversion. (Note: svn must be in path) 
 
1.5 Plugins
 script/plugin discover
 # discover plugin repositories
 script/plugin list
 # list all available plugins
 script/plugin install where
 # install the a€wherea€? plugin
 script/plugin install -x where
 # install where plugin as SVN external
 script/plugin install http://invisible.ch/projects/plugins/where
 script/plugin update
 # update installed plugins
 script/plugin source
 # add a source repository
 script/plugin unsource
 # removes a source repository
 script/plugin sources
 # lists source repositories

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.