執行rake secret 在.bashrc 或在apache 使用SetEnv指令 設定環境變數 SECRET_KEY_BASE 就完成了。不建議把 secret token 設定在 config/secrets.yml
3/14/15Less than 1 minute
執行rake secret 在.bashrc 或在apache 使用SetEnv指令 設定環境變數 SECRET_KEY_BASE 就完成了。不建議把 secret token 設定在 config/secrets.yml
根據https://github.com/bundler/bundler/blob/master/ISSUES.md,解決方是執行以下程式碼,重新安裝 dependencies :
# remove user-specific gems and git repos
rm -rf ~/.bundle/ ~/.gem/bundler/ ~/.gems/cache/bundler/
# remove system-wide git repos and git checkouts
rm -rf $GEM_HOME/bundler/ $GEM_HOME/cache/bundler/
# remove project-specific settings
rm -rf .bundle/
# remove project-specific cached gems and repos
rm -rf vendor/cache/
# remove the saved resolve of the Gemfile
rm -rf Gemfile.lock
# uninstall the rubygems-bundler and open_gem gems
rvm gemset use global # if using rvm
gem uninstall rubygems-bundler open_gem
# try to install one more time
bundle install
主要在Gemfile加下以下指令以安裝 babosa
gem "babosa"
再在需要中文URL的Model下override normalize_friendly_id方法:
def normalize_friendly_id(input)
input.to_s.to_slug.normalize.to_s
end
以下網誌有詳細解釋:
使用 Babosa 配合 Friendly_id 解決中文網址問題 : http://blog.roachking.net/blog/2014/01/17/babosa-friendly-id-solve-chinese-problems/
假設我們要改變sub_anonrums table的title,將其欄位種類由:text改為:string方法如下:
1.在project下新增一個migration file
rails g migration change_sub_anonrums_title_format
2.移除migration 下的change 方法,改為使用up 和down方法,migration file 的source code 如下所示: \
class ChangeSubAnonrumsTitleFormat < ActiveRecord::Migration
def up
change_column :sub_anonrums, :title, :string
end
def down
change_column :sub_anonrums, :title, :text
end
end
3.執行 rake db:migrate