ITeye博客

fei1985

fei1985 · 共 27 篇文章

[置顶] What is mattr_accessor in a Rails module?

module Config mattr_accessor :hostname mattr_accessor :admin_email end #s short for: module Config def self.hostname @@hostname end def self.hostname=(hostname) @@hostname = hostname end def self.admin_email @@admin_email end def self.admin_email=(admin_email) @@admin_email end end >> Config.hostna…

2008-10-30 13:52 · rails · 评论(0) · Rails

facebox.js 添加新功能

使用facebox时, 我们要点击关闭按钮时, 遮罩层才消失, 默认是没有这个功能的.这个功能很简单,就是阻止关闭事件的触发就行了. 首先在settings加入默认值,方便我们使用的时候定置效果 settings: { opacity : 0, overlay : true, modal : true, loadingImage : '/images/facebox/loading.gif', closeImage : '/images/facebox/closelabel.gif', imageTypes : [ 'png', 'jpg', 'jpeg', 'gif' ], facebox…

2010-04-22 11:40 · jquery · 评论(0) · CSS

rails 自定义配置

time formate Time::DATE_FORMATS[:month_and_year] = "%B %Y" Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") } error_messages ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag } 在rails3中要加html_safe

2010-04-11 20:37 · 评论(0) · HTML · Rails

rails 3 新的 验证写法

在源文件中看到新的写法 和前面相差很多, 不过老方案在rails3也不会出错 Examples of using the default rails validators: validates :terms, :acceptance => true validates :password, :confirmation => true validates :username, :exclusion => { :in => %w(admin superuser) } validates :email, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9…

2010-04-10 23:25 · 评论(0) · Rails

关于returning

在beast的记录中看到一个方面中用到returning的用法。 def reply(topic, body) returning topic.posts.build(:body => body) do |post| post.forum = topic.forum post.user = self post.save end end 有点不是很理解。在google中收到这篇文章是关于returning的说明的 http://weblog.jamisbuck.org/2006/10/27/mining-activesupport-object-returning def returning(…

2010-04-09 23:52 · rails · 评论(0) · Google

记录下来关于for each区别

http://www.letrails.cn/archives/difference-between-for-loop-and-each/ 上看到 for和each的区别主要在于: for是通过调用each实现,因此for更慢一些 for会在each的scope之外创建一个局部变量,这在某些情况下会引发问题 关于第二点,下面的代码可以很好的说明这个问题: irb> [1, 2, 3].each do |m| puts m end irb> puts m NameError: undefined local variable or method `m' for main:Object irb>…

2010-04-09 23:51 · rails · 评论(0) · Ruby

rails3 路由笔记

rails3 路由发生了剧大的变化, 是居于项目名称的 Redmine::Application.routes.draw do |map| rest路由eg. resources :trackers #简单路由: match '/projects#edit' => 'projects#settings' #post方法的路由: post "my/order_blocks" #get 方法的路由: get "/my/page" #namespace 路由 namespace :admin do resources :users resources :projects end #首页路由 roo…

2010-04-09 23:41 · 评论(0) · REST · Rails

rails 3 activerecord new interface

In short, passing options hash containing :conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :having, :from, :lock to any of the ActiveRecord provided class methods, is now deprecated. Going into details, currently ActiveRecord provides the following finder methods …

2010-04-09 15:39 · 评论(0) · Cache · Rails · ActiveRecord

ruby 中尽量少于nil?

ruby是灵活的,同样的效果花的代价却是不同的请看下面的例子: require 'benchmark' Benchmark.bm do|b| b.report("without .nil?") do cat = nil bat = 'vampire' 2_000_000.times do unless bat true if cat end end end b.report("with nil? ") do cat = nil bat = 'vampire' 2_000_000.times do unless bat.nil? true unless cat.nil? end end end…

2009-10-31 20:14 · rails · 评论(1) · Ruby

41条帮你提高网站排名

1、关键词 关键词在网站TITLE上的使用 2、外部链接 外部链接的锚文字 3、网站品质 网站的外部链接流行度、广泛度 4、网站品质 域名年龄(从被搜索引擎索引开始计算) 5、页面质量 网站内部链接结构 6、网站品质 网站的外部链接页面内容与关键词的相关性 7、网站品质 网站在主题相关的网站群中的链接流行度 8、关键词 关键词在网页内容上的应用 9、外部链接 外部链接页面本身的链接流行度 10、网站品质 网站新外部链接产生的速率 11、页面质量 导出链接的质量和相关性 12、外部链接 外部链接页面的主题性 13、外部链接 外部链接页面在相关主题的网站社区中的链接流行度 14、关键词 页面内容…

2009-10-31 20:00 · Css · 评论(0) · HTML · Google · 搜索引擎

jquery 1.3 的 live方法

jQuery 1.3中新增的方法。给所有当前以及将来会匹配的元素绑定一个事件处理函数(比如click事件)。也能绑定自定义事件。 目前支持 click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup。 还不支持 blur, focus, mouseenter, mouseleave, change, submit ,与bind()不同的是,live()一次只能绑定一个事件。 这个方法跟传统的bind很像,区别在于用live来绑定事件会给所有当前以及将来在页面上的元素…

2009-10-31 14:01 · jquery · 评论(0) · jQuery

mysql优化之硬件篇

mysql的速度优化中,我们首先从硬件来提高我们的 mysql的速度。常见的系统瓶颈如下 磁盘搜索。需要花时间从磁盘上找到一个数据,优化它的方法是将数据分布在多个磁盘上,组成磁盘矩阵,提升了更高的存储性能,也提高了数据的安全性。 磁盘读/ 写。对于现代的磁盘,一个磁盘至少传输10-20Mb/s 的吞吐。提高磁盘的速度提升myql. CPU 周期。周期越小,从内存中读写的数据越高 内存大小。当然是越大载好了。当然内存还有很多参数了。 总体来说 性能强的机器mysql的运行速度也越高。当然这个需要G的支持,大部份情况下我们应该优化数据库表的设计,相关系统参数配置,相关mysql 语句的一些优化,…

2009-10-30 01:48 · mysql · 评论(0) · MySQL

【收藏】jQuery性能优化指南

1,总是从ID选择器开始继承 2,在class前使用tag(标签名) 3,将jQuery对象缓存起来(在多次使用是,用一个中间变量代替,而不是总是用选择器) 4,对直接的DOM操作进行限制 5,注意尽量减少事件冒泡 6,推迟到 $(window).load 7,压缩JavaScript 8,尽量使用ID代替Class。 9,给选择器一个上下文 10,慎用 .live()方法(应该说尽量不要使用) 11,子选择器和后代选择器 12,使用data()方法存储临时变量

2009-10-14 01:27 · 评论(0) · jQuery · JavaScript

rjs 中的一些记下 免的忘 了

有能不全 常用效果 page.insert_html :bottom, "list", "<li>hello</li>" page.visual_effect :highlight, "list" page.hide "list" page.remove "list" page.replace "id", :partial => "template" page.replace_html "id", :partial => "template" page.toggle "id(s)" 在jrails中还有 page.jquery_id(id) page.jquery_ids(*id) eg.p…

2009-10-07 23:03 · rails · 评论(0) · HTML · UP · prototype · jQuery · JavaScript

在判定结果长度时最好用length

有时一些结果长度的判定。 选择有很多,像size, length, empty?,any?等等 如果在controller.rb 你有了 @users = User.activate 在view中 1.使用size if @users.size > 0 会产生2条sql 但length不会

2009-10-05 09:54 · rails · 评论(0) · SQL