def status_time_ago_in_words(time) time = time_ago_in_words(time) case time when "less than a minute" "刚刚" when /minute/ time.gsub(/minute|minutes/,'分钟') + "前" when /hour/ ##time.gsub(/about/,'').gsub(/hours/,'小时') + "前" time.gsub(/about (\d+) (hour|hours)/, '\1小时') + "前后" when "1 day" "昨天" when "2 days" "前天" else time.gsub(/days/,'天') + "前" end nd
wer
case request.method when :post Emailer.deliver_contact('[email protected]', 'Please active your Account','send message','http://www.baidu.com') end
字符集转换 require 'iconv' conv = Iconv.new("gbk", "utf-8") puts conv.iconv(q) 让页面延迟两秒发送,目地让数据加载完毕 # render as finished responds_to_parent do # execute the redirect in the main window render :update do |page| page.call "UploadProgress.setAsFinished" page.delay(2) do # allow the progress bar fade to complete page.redirect_to url_for(:action => "complete") end end end ruby 的case 方法与request 结合 case request.method when :post Emailer.deliver_contact('[email protected]', 'Please active your Account','send message','http://www.baidu.com') end
ruby在用当前action执行Ajx请求 respond_to do |format| format.html # index.html.erb format.xml { render :xml => @contracts } format.js { render :update do |page| page.replace("list" , :partial => "list" ) end } end
evel函数 eval(" page.replace('image#{picture_position}',image_tag('/upload/'+'# {name}',:id=>'image#{picture_position}',:width=>180,:height=>130)) page.replace('product_image#{picture_position}',hidden_field (:product, :image#{picture_position},:value=>'/upload/#{name}')) ") page.call("top_alert","#{:image_null_input_error.l()}") var x = document.getElementById('abc'); name = x.childNodes[x.childNodes.length-1].name; setTimeout('myol()',4000); function myol() { var mytag = window.frames[name].document.getElementsByTagName ('a'); alert(mytag[0].href); } <%= select(:contract, :department_id, @depart ,{}, { "onchange" => remote_function( :with => "'parent_id='+value", # :update => 'county_select', #:complete => "Element.show('county_select')", :url => { :action => :select_with_ajax1 } ) })%> <%=option_groups_from_collection_for_select(@allgroups, :members, :name, :full_name, :full_name,s @selected_manager) %> 取随机数 chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789' randchar = '' length.downto(1) { |i| randchar<< chars[rand(chars.length - 1)] } def self.generate_randchar(length=6) chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789' randchar = '' length.downto(1) { |i| randchar<< chars[rand(chars.length - 1)] } randchar end def self.base_part_of(file_name) File.basename(file_name).gsub(/[^\w._-]/, '') end