顯示具有 rails 標籤的文章。 顯示所有文章
顯示具有 rails 標籤的文章。 顯示所有文章

2011年5月5日 星期四

Rails 一般輸入框簡單驗證法

<%=h text_field("", :number, :size => 10, :onkeyup => "if(isNaN($('#_number').val())){ alert('请输入数字'); $('#_number').val('');}" ) %>

2011年2月15日 星期二

rails 送出時的錯誤

發生ActionController::InvalidAuthenticityToken時

在Controller上面加入
protect_from_forgery :except => :index

# you can disable csrf protection on controller-by-controller basis: skip_before_filter :verify_authenticity_token

2011年2月13日 星期日

git做branch的流程

git branch 20100214 轉到分支20100214
git branch show出所有的支架
git branch -a show出所有的支架(連同remote)
git checkout -b v2011021501-bookjob remotes/origin/v2011021501-bookjob 將remotes的某分支下載到local分支,如果有這分支名稱的話請執行xxxxxxxx
git checkout 20100214 轉到某支架
git merge 20100214 將master和20100214合併
git branch -d 20100214 在local刪除20100214分支
git push origin v20110217-prepay 把v20110217-prepay上到remote的origin
git pull -a 下載remote資訊

git push

2010年11月18日 星期四

whenever - Cron in Ruby

其實雖說是Cron in Ruby,但卻都用在Rails上lol
Github
Railscasts - Cron in Ruby
以下內容擷取自Railscasts

先在config/environment.rb中加入這段
複製內容到剪貼板
代碼:
# config/environment.rb
config.gem 'javan-whenever', :lib => false, :source => 'http://gems.github.com'
然後下
複製內容到剪貼板
代碼:
# 這表示Windows與此無緣
sudo rake gems:install
之後,在你的Project根目錄中下此指令
複製內容到剪貼板
代碼:
wheneverize .
然後會在config/底下產生一個schedule.rb,編輯它
複製內容到剪貼板
代碼:
every 2.hours do
rake "thinking_sphinx:index"
end

every :reboot do
rake "thinking_sphinx:start"
end

every :saturday, :at => "4:38am" do
command "rm -rf #{RAILS_ROOT}/tmp/cache"
runner "Cart.remove_abandoned"
end

# config/deploy.rb
after "deploy:symlink", "deploy:update_crontab"

namespace :deploy do
desc "Update the crontab file"
task :update_crontab, :roles => :db do
run "cd #{release_path} && whenever --update-crontab #{application}"
end
end
然後儲存離開,跳出來後下
複製內容到剪貼板
代碼:
whenever --update-crontab
接著再下
複製內容到剪貼板
代碼:
crontab -l
看有沒有出現

基本上,用every設定時間必須大於等於60秒,也就是1分鐘,用小於1分鐘就會出問題





rake -T
http://en.wikipedia.org/wiki/Rake_(software)

task :addproduct => :environment (for ActiveRecord)



排程:
linux cron table

分 時 日 月 年 星期 command
*/5 * * * * *

http://rubydoc.info/gems/whenever/0.6.2/frames
/var/log
whenever --update-crontab -s environment=development
crontab -l

2010年11月4日 星期四

Rails在正式環境做migrate指令

rake db:migrate RAILS_ENV=production