rails学习笔记
jackdong · 共 9 篇文章
nokogiri抓取网络资源
写道 Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser. Among Nokogiri’s many features is the ability to search documents via XPath or CSS3 selectors. XML is like violence - if it doesn’t solve your problems, you are not using enough of it. Nokogiri 的解析能力+open-uri的网络访问想组合就可以用来抓取网络上的一些资源了,下面的这段代码用来…
2010-08-25 10:18 · rails2 · 评论(0)
利用paperclip实现kindEditoer的图片上传和浏览
KindEditor 是一款优秀的开源HTML编辑器, 它的图片上传和浏览是利用插件的方式进行的。编辑器的参数中imageUploadJson定义了图片上传的后台程序地址, allowFileManager 定义了是否允许浏览服务器图片,fileManagerJson指定了浏览图片时后台程序地址。以下代码根据个人情况应该有所不同。 写道 {"error":1, "url":"URL"}图片上传成功返回的字符串 {"error":0} 上传失败返回的字符串 下面是KindEditor Demo里面后台地址返回的json字符串。图片浏览是通过plugins/file_manager/file_m…
2010-08-25 10:11 · rails2 · 评论(0)
strip_tags
strip_tags (html) Strips all HTML tags from the html , including comments. This uses the html-scanner tokenizer and so its HTML parsing ability is limited by that of html-scanner. strip_tags("Strip <i>these</i> tags!") # => Strip these tags! strip_tags("<b>Bold</b> no more! <a href='more.html'>See …
2010-05-06 22:23 · rails2 · 评论(0)
format time
ri Time.strftime ------------------------------------------------------- Time#strftime time.strftime( string ) => string --------------------------------------------------------------------- Formats _time_ according to the directives in the given format string. Any text not listed as a directive wi…
2010-04-21 13:33 · Ruby学习总结 · 评论(0)
笔记:named_scope的用法
转自 muyu 的bolg, 学习并记录以备日后查询使用。 named_scope 与 paginate 联合使用 class Product < ActiveRecord::Base named_scope :online, :conditions => {:status => 1}, :include => [:variants, :catalogue_images, :categories] named_scope :from_category_ids, lambda { |cat_ids| {:conditions => "categories_products.category_i…
2010-03-15 23:03 · rails2 · 评论(0)
【翻译】railscasts 136:jQuery
136: jQuery 原版railscasts ------------------------------------------------------------------------------------------------------------------------------ 翻译的过程中查询了一些资料,得知如果$.post()设置dataType为‘script',就可以返回纯文本 JavaScript 代码,不用再设置MIME信息。 第一次翻译,鸟语和技术水平有限,非逐字逐句翻译,只是想用自己的话把作者的意思表达出来。译文难免存有纰漏,还请多多指正。 -----…
2010-03-11 23:45 · rails2 · 评论(0)
paperclip学习使用笔记
paperclip 是rails处理附件的一个插件, 相对于以往的 attachment_fu 等在效率和使用上更胜一筹。 paperclip 上传的图片附件如果不需要进行改变大小等操作, 则不需要安装ImageMagick。paperclip在window平台下进行图片处理很容易得到这样的错误信息 。。。is not recognized by the 'identify' command 花了1.5h 终于在一个被墙的blog上找到这样的一个解决办法: 在项目的config/iniinitializers目录下面新建一个paperclip.rb文件 并写入如下代码: Paperclip.…
2010-03-07 22:43 · rails2 · 评论(0)
最大公约数
k = f(x, y)求最大公约数 1. 假设x = m*x1 m为质数且 y%m!=0, 所以k = f(m*x1, y) = f(x1, y) 2. 如果x = m*x1, y = m*y1, 所以 k = f(m*x1, m*y1) = m* f(x1, y1) 3. 如果不同时满足上述2点 则 k = f(x, y) = f(y, x-y) (x>=y) private static boolean isEven(int num) { return num%2==0 ? true : false; } private static int gcd(int m, int n) { if…
2009-10-09 23:51 · 算法总结 · 评论(0)
Java Double相加出现的怪事
问题的提出: 编译运行下面这个程序会看到什么 public class test { public static void main(String args[]) { System.out.println(0.05 + 0.01); System.out.println(1.0 - 0.42); System.out.println(4.015 * 100); System.out.println(123.3 / 100); } }; 你没有看错!结果确实是 0.060000000000000005 0.5800000000000001 401.49999999999994 1.232999…
2009-09-28 16:39 · Java · 评论(3)