- 浏览: 164757 次
- 性别:
- 来自: 杭州
最新评论
-
GunChin:
有些复杂,看得不是很懂
RAILS -
shellfish:
恩,红帽默认的SELinux的级别是强制,这个一般我不大用,装 ...
华思服务器一个奇怪问题的解决方法 -
机器人:
你说得太好了了了了了了了 子 啊啊啊啊,呼啦啦。
GIT handbook -
hbxiao135:
能介绍下 fat free crm的 流程分析吗?
(CRM)customer relationship management sysetm
文章列表
REST on Rails之自定义路由
from LetRails
by admin
要扩展你的REST路由,可以通过设置map.resource的:collection,:member或者:new选项来实现:
map.resources :projects, :collection => {:rss => 'get'}
map.resources :projects, :member => {:close => 'post'}
map.resources :projects, :new => {:validate => 'pos ...
- 2009-06-03 10:03
- 浏览 1693
- 评论(0)
Ruby技巧3则
from LetRails
by yuanyi
1. 构造正则
我们都知道,可以通过一下两种方式来构造正则:
irb> /ruby/
=> /ruby/
irb> Regexp.new('ruby')
=> /ruby/
但实际上还有一种:
irb> %r{ruby}
=> /ruby/
如同%w, %q一样,%r将一个字符串转换为一个正则,并且你不止可以使用{}作为起始,结束符:
irb> %r!ruby!
=> /ruby/
irb> % ...
- 2009-06-03 09:59
- 浏览 905
- 评论(0)
自定义will_paginage输出
from LetRails
by yuanyi
will_paginate
是Rails中比较常用的分页插件,但是有时候我们可能想要自定义它的输出,这可以通过扩展WillPaginate::LinkRenderer类来实现,比如,下面的renderer将会去除Next和Previous链接(来自这里
):
class CustomPaginationRenderer < WillPaginate::LinkRenderer
def to_html
links = @options[:page ...
- 2009-06-03 09:55
- 浏览 793
- 评论(0)
theme_support: 为Rails应用添加theme支持
from LetRails
by yuanyi
theme_support是Matt McCray
写的一个为Rails应用增加类似Typo的theme管理的插件,功能类似于Typo,支持liquid
和erb模板。
安装
$ script/plugin install http://mattmccray.com/svn/rails/plugins/theme_support
使用
1. 生成主题
$ script/generate theme [theme_name] ...
- 2009-06-03 09:51
- 浏览 1321
- 评论(0)
Rails Cookie测试
from LetRails
by yuanyi
如果你在某个action中对Cookie进行了设置,然后你又打算对你设置的cookie进行测试,那么你可能会遇到麻烦,不妨看看下面这段代码:
class CookiesController
def update
cookies[:name ...
- 2009-06-03 09:48
- 浏览 1083
- 评论(0)
配置ActionMailer使用GMail发送邮件
from LetRails
by admin
这个问题由来已久,比较了一下几种现有的解决方案,最后发现Robert Bousquet
的方案是最简单的。
1. Robert只提供了一个源码下载链接,不是很方便,我将它放到了github上:
$ script/plugin install git://github.com/yzhang/smtp_tls.git
2. 修改environment.rb:
require "smtp_tls"
mailer_con ...
- 2009-06-03 09:45
- 浏览 1461
- 评论(0)
使用rails_reviewer优化Rails数据库查询性能
from LetRails
by yuanyi
最近在做的一个项目遇到严重的性能问题,主要是数据库查询过多,同事向我推荐了rails_reviewer
插件,它是我的前同事(不确定我进公司时他还在不在) D ...
- 2009-06-03 09:39
- 浏览 1340
- 评论(0)
city_helper: 省市二级联动Select插件
from LetRails
by yuanyi
city_helper提供了几个简单的helper来实现省及城市的二级联动select,目前只支持国内城市,经过测试的浏览器:FF3, Chrome 2 beta, IE7,
Safari 4。
安装
$ script/plugin install git://github.com/yzhang/city_helper.git
使用
安装之后,你就可以在View中直接使用以下Helper了:
state_select :user, :st ...
- 2009-06-03 09:36
- 浏览 1484
- 评论(0)
github address: http://github.com/CodeOfficer/js-data-helper/tree/master
What Is It?
It’s a Rails plugin that will help you pass data from Rails to Javascript.
Requirements
JS Data Helper requires either jQuery
1.2.3+, Prototype
1.6.1+ or Mootools
1.2+. Each of those Javascript framework ...
- 2009-06-03 09:12
- 浏览 925
- 评论(0)
function toggle_menu(obj){
var p = obj.parentNode;
var s = p.down(4);
if(p.hasClassName('inactive')) {
p.removeClassName('inactive');
p.addClassName('active');
s.removeClassName('expend');
s.addClassName(' ...
- 2009-06-03 08:51
- 浏览 1475
- 评论(0)
def store_location
session[:return_to] = request.request_uri
end
# Redirect to the URI stored by the most recent store_location call or
# to the passed default.
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:retu ...
- 2009-06-02 13:44
- 浏览 1388
- 评论(0)
对于非ActiveRecord对象的Validation,我们不能简单的include ActiveRecord::Validations
我们需要写一个module,放到lib下面,创建一个validateable.rb
module Validateable
[:save, :save!, :update_attribute].each{|attr| define_method(attr){}}
def method_missing(symbol, *params)
if(symbol.to_s =~ /(.*)_before_type_cast$/)
...
- 2009-06-02 09:33
- 浏览 894
- 评论(0)
If you search for ways to become a better developer
you will find nearly 70 million results. After reading as many of those
results as possible and still learn something, I boiled down all the
advice to the following general axioms.
Read Everything
Learn Fast, Learn Everything
Pract ...
- 2009-06-01 16:40
- 浏览 789
- 评论(0)
alias vncmybox=’
vncviewer admin@192.168.245.231′
Now you have created your first alias. Anytime during the session you type vncmybox
it will run the command we assigned to that alias.
Here is the catch, as soon as you close the terminal all is lost.
Let’s make this change permanent.
Go to y ...
- 2009-05-13 15:32
- 浏览 1112
- 评论(0)
1、最常用的是each each_with_index
ss = [1,2,3,4,5]
ss.each do |s|
puts s
end
ss.each_with_index do |s,i|
puts ss[i]
end
2、case(switch)语句
case x
when "this"
func_this_that()
when "that"
func_this_that()
when "nothing"
# something different
e ...
- 2009-04-23 14:07
- 浏览 1139
- 评论(0)