项目摘抄

belongs_to :user, :inverse_of => :topics

counter_cache :name => :user, :inverse_of => :topics



受保护属性,不能接受页面参数

attr_protected :user_id

scope :last_actived, desc("replied_at").desc("created_at")



controller:

caches_page :feed, :node_feed, :expires_in => 1.hours




国际化:

初始化:

I18n.default_locale = :en


LANGUAGES = [
['English', 'en'],
["Español".html_safe, 'es']
]


气质过滤器:

def set_i18n_locale_from_params
if params[:locale]
if I18n.available_locales.include?(params[:locale].to_sym)
I18n.locale = params[:locale]
else
flash.now[:notice] =
"#{params[:locale]} translation not available"
logger.error flash.now[:notice]
end
end



自增:(计数器)

@topic.hits.incr(1)

counter :hits, :default => 0



防止crsf攻击:

protect_from_forgery ----controller

<%= csrf_meta_tag %> --layout


发起其他方式提交:标签用

auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})


分词插件:RMMSeg::Algorithm


input=text 默认显示字体 设置 :placeholder =>"xianshi"

你可能感兴趣的:(项目)