`
andyhu1007
  • 浏览: 200871 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Rails每周闲碎(四): Architecture

阅读更多

1. $:    =》 Rails's load path

 

2. reload

   Reloads the attributes of this object from the database. The optional options argument is passed to find when reloading so you may do e.g. record.reload(:lock => true) to reload the same record with an exclusive row lock.

 

   When do you need to do reload? When you hold a object whose state may be changed by others.

 

3. cache_classes

 

    为什么development环境下,改动代码但却不需要重启服务器生效?

 

    cache_classes = false

 

 

4. observers的注册

 

#  in environment.rb
config.active_record.observers = :user_observer

 

5. Table name convention

 

     how if you don't want to use rails's convention: pluralize table name.

 

 

# in environment.rb
config.activerecord.pluralize_table_names = false

 

6. Env Constant

 

    How to set rails environment variable? it's just easy to add a constant in environment.rb.

 

 

LINGKOU_ENV = {
          :image_root => "/images" 
 }

 

    and you can then access this environment anywhere else

 

7. rescue_action_in_public

 

    当 controller抛出exception时,它会调用这个方法。重载这个方法,正是定制程序自己的404或者505等错误页面的方式。

 


8. freeze 

 

    不要让版本的变换扰乱你的开发,把你的rails等其它gems freeze到vendor下面。

 

    http://www.softiesonrails.com/2008/1/3/freezing-your-rails-application

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics