在rails中,当我们请求页面的时候,rails会生成一个随机的authenticity_token保存在session中,当我们向服务器发出post ,put ,delete请求的时候,它就会验证session中存储的值,如果匹配,则继续流程。
这主要是为了防止Cross Site Request Forgery攻击。阻止用户进行非表单提交的操作。。具体见:rails-authenticity-token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gem cleanup 用来清除旧版本的 gem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://blog.csdn.net/lu7kang/archive/2010/01/26/5258054.aspx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cat log/test_oracle.log |grep "200 OK" | awk '{print $11}'|sort|uniq -c | sort -n -r |
ApplematoMacBook-Pro:~ Apple$ sudo brew install mongodb
Warning: It appears you have MacPorts or Fink installed.
Software installed with MacPorts and Fink are known to cause problems.
If you experience issues try uninstalling these tools.
==> Downloading http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-1.6.4.tgz
- 100.0%
==> Caveats
If this is your first install, automatically load on login with:
cp /usr/local/Cellar/mongodb/1.6.4-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 我们可以通过重载rails 的rescue_action_in_public 方面,自定义,我们的异常处理,它默认情况会调用 | |
| render_optional_error_file去渲染400,500页面。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #重构:实现为类动态增加方法 | |
| module A | |
| def self.included(target) | |
| target.extent(ClassMethods) | |
| end | |
| module ClassMethods | |
| def .. | |
| end | |
| end |
- 首先安装rvm,这个和在linux上安装是一致的,安装完成之后,将 if [[ -s /Users/Apple/.rvm/scripts/rvm ]] ; then source /Users/Apple/.rvm/scripts/rvm ; fi 放在~/.bash_profile中。
- rvm 1.9.2 —default
- 参见前面安装rails 3
- bundle install (在项目目录下执行,注意将Gemfile文件里的rb-inotify这个gem注释调,因为它还不支持os x平台)
- 安装homebrew,具体步骤见:安装homebrew ,homebrew安装东西比macport要快很多。
- sudo brew install ImageMagick
- sudo brew install mongodb (具体步骤见:安装mongodb )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/models/abstract_server.rb | |
| class AbstractServer < ActiveRecord::Base | |
| self.abstract_class = true | |
| validates_presence_of :name, :address, :username, :password, :encoding | |
| validates_length_of :name, :maximum => 20, :allow_blank => true | |
| validates_length_of :address, :maximum => 20, :allow_blank => true | |
| validates_length_of :username, :password, :maximum => 20, :allow_blank => true | |
| validates_length_of :encoding, :maximum => 10, :allow_blank => true |
由于,觉得用textmate还是不大习惯,所以,还是决定把macvim安装上,首先,在安装之前,我们现查看一下vim包的variants。
ApplematoMacBook-Pro:~ Apple$ port variants vim
vim has the variants:
athena: Build GUI version using Athena widgets
- conflicts with gtk1 gtk2 motif
- requires x11
big: Build big feature set - conflicts with small tiny
cscope: Enable source code browsing with cscope