- 浏览: 35582 次
- 性别:
- 来自: 上海
最新评论
-
shengh123:
当时装will-paginate的时候好像有点问题。其他的都是 ...
will_paginate 搜索结果分页 -
tyrael:
请问,有没有好的办法判断字符串的值是否为数字?
比如,3、1. ...
ruby字符串处理
文章列表
PS:下面是转过来的,用于记录下,这个不是正则的初衷,只是用了REGEXP而已,正则的更灵活更方便
将comment表中的author_url包含www.sohu.com的记录,其中的sohu替换为sina,一个语句搞定~
update comment set author_url=REPLACE(author_url,'sohu','sina') where author_url REGEXP 'www.sohu.com';
带IF判断的复杂替换
update comment set url=IF(url REGEXP 'test.yahoo.com.cn',REPLACE(url,'ww ...
- 2009-06-06 08:23
- 浏览 883
- 评论(0)
一、date_select(object_name,method,options={},html_options={})
1、use_month_numbers
用法: :use_month_numbers=>true
月份默认以英文形式显示,当该属性设置为true后,则以数字的形式显示;
2、start_year
用法: :start_year=>1990
默认的起始年为当年减5年;若要自己设定,可以用start_year进行设定;
3、end_year
与start_year类似
4、discard_day
:discard_day=>true
去除年、月、日选项中的“日” ...
- 2009-06-05 16:32
- 浏览 808
- 评论(0)
has_attached_file :avatar,
:styles => { :medium => "200x200>", :thumb => "100x100>" }
validates_attachment_content_type :avatar,
:content_type => ['image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png'],
:message => &quo ...
- 2009-05-20 10:09
- 浏览 880
- 评论(0)
1. ------------------------------------------------------- Time#strftime
2. time.strftime( string ) => string
3. ---------------------------------------------------------------------
4. Formats _time_ according to the directives in the given format
5. ...
- 2009-05-13 09:43
- 浏览 816
- 评论(0)
@client_ip = request.env["HTTP_X_FORWARDED_FOR"] #取得使用者IP位址資訊
@client_browser = request.env["HTTP_USER_AGENT"] #取得使用者瀏覽器資訊
@http_referer = request.env["HTTP_REFERER"] #取得使用者來源(referer)
@client_language = request.env["HTTP_ACCEPT_LANGUAGE"] #取得使用者支援語系
@serve ...
- 2009-04-10 13:27
- 浏览 771
- 评论(0)
1 select * from sells where date_sub(curdate(),interval 14 day)<= date(created_at)
2 select * from sells where to_days(now())-to_days(created_at) < 14
- 2009-03-21 21:48
- 浏览 2391
- 评论(0)
<%= javascript_include_tag 'prototype' %>
<% form_tag '/sell/index', :method => :get do %>
<%= select_tag "id", options_for_select({'1' => 1, '2' => 2, '3' => 3}), { :index => nil,nchange => 'this.form.submit()',:with => "'id='+value"} %> ...
- 2009-03-21 19:51
- 浏览 917
- 评论(0)
4,dynamic layout
有时候我们需要根据不同的用户角色来使用不同的layout,比如管理员和一般用户,比如博客换肤(也可以用更高级的theme-generator)
代码
1. class ProjectsController < ApplicationController
2. layout :user_layout
3.
4. def index
5. @projects = Project.find(:all)
6. end
7.
8. protected
...
- 2009-03-08 15:42
- 浏览 616
- 评论(0)
今天在做一个产品和订单的多对多关系中,在提交view中使用如下代码
<% for product in @products %>
<div>
<%= check_box_tag "order[product_ids][]", product.id, @order.products.include?(product) %>
<%= product.name %>
</div>
...
undefined method `relative_url_root' for #<ActionController::CgiRequest:0x23b026>
There is been a Fix for Rails 2.2
in the file app/controllers/fckeditor_controller.rb
look for
uploaded = request.relative_url_root.to_s+"#{UPLOADED}/#{params[:Type]}"
replace it with this
uploaded = ...
- 2009-02-24 23:01
- 浏览 1197
- 评论(0)
will_paginate 搜索结果分页
Rails分页plugin之will_paginate
搜索结果的分页显示是一个常用功能,实现方式有很多中,rails也内建了对分页的支持,但是rails2.0将去掉分页组件,将分页功能交给 plugin去实现,这里通过一个简单的例子展示如何使用最流行的rails分页plugin -- will_paginate.
1.安装will_paginate,编写分页代码
安装:
ruby script\plugin install svn://errtheblog.com/svn/plugins/will_paginate安装成功后,开始编写分页代码
修 ...
- 2009-02-14 14:58
- 浏览 1844
- 评论(1)
下拉框ajax特效
在layout主模板或者view中加入<%= javascript_include_tag 'prototype' %>
在需要放置下拉框的地方设置
<%= collection_select(:member, :company_province, @province, :provinceid, :province,options ={:prompt => '一级分类'},
html_options = {:onChange => remote_function(:update => "person_area ...
- 2009-02-11 21:32
- 浏览 1456
- 评论(0)
Date
====
db:'%Y-%m-%d' 2008-08-20
long_ordinal:'&proc' August 20th, 2008
long:'%B %e, %Y' August 20, 2008
rfc822:'%e %b %Y' 20 Aug 2008
number:'%Y%m%d' 20080820
short:'%e %b' 20 Aug
DateTime
========
db:'%Y-%m-%d' ...
- 2009-02-06 09:49
- 浏览 1211
- 评论(0)