- 浏览: 113347 次
- 性别:
- 来自: 火星
文章分类
最新评论
-
hexawing:
相当好的入门级文章,收藏学习了!
rake任務詳解 -
minn84:
...
2012目标 -
luopeng_sg:
请问LZ这用的是JRuby还是CRuby呢?
验证码生成插件simple_captcha -
orcl_zhang:
2套?有钱人。100本,貌似有点多。
2012目标 -
keating:
来捣乱
要有梦
有时候听歌听的入迷了,就想下载google的歌词,可是下下来总是这个样子...
一个一个的修改删除,这多没劲啊...所以...
config\initializers目录下建立一个custom_requires.rb,然后...
例如:G:\Program Files\ImageMagick-6.5.6-Q8
应填入-->(不支持空格)
详细参考-->
Paperclip提示command is not recognized by the 'identify
http://hot88zh.iteye.com/blog/859238
或
引用
[00:17.00]有时后我觉得自己像一只小小鸟
[00:23.00]想要飞 却怎么样也飞不高
[00:30.00]也许有一天我栖上枝头 却成为猎人的目标
[00:36.00]我飞上了青天才发现自己从此无依无靠
[00:43.00]每次到了夜深人静的时候我总是睡不着
[00:50.00]我怀疑是不是只有我的明天没有变得更好
[00:56.00]未来会怎样究竟有谁会知道
[01:03.00]幸福是否只是一种传说 我永远都找不到
[01:10.00]我是一只小小小小鸟 想要飞呀飞却飞也飞不高
[01:24.00]我寻寻觅觅寻寻觅觅一个温暖的怀抱
[01:29.00]这样的要求算不算太高
[01:37.00]我是一只小小小小鸟 想要飞呀飞却飞也飞不高
[01:51.00]我寻寻觅觅寻寻觅觅一个温暖的怀抱
[01:56.00]这样的要求算不算太高
[02:03.43]所有知道我的名字的人啊你们好不好
[02:27.33]所有知道我的名字的人啊你们好不好
[02:33.29]世界是如此的小 我们注定无处可逃
[02:40.20]当我 尽人情冷暖 当你决定为你了的理想燃烧
[02:46.67]生活的压力与生命的尊严哪一个重要
[02:54.36]我是一只小小小小鸟 想要飞呀飞却飞也飞不高
[03:07.10]我寻寻觅觅寻寻觅觅一个温暖的怀抱
[03:13.22]这样的要求算不算太高
[03:21.00]我是一只小小小小鸟 想要飞呀飞却飞也飞不高
[03:33.90]我寻寻觅觅寻寻觅觅一个温暖的怀抱
[03:40.31]这样的要求算不算太高
[03:46.17]所有知道我的名字的人啊你们好不好
[03:47.05]这样的要求算不算太高
[03:58.43]所有知道我的名字的人啊你们好不好
[00:23.00]想要飞 却怎么样也飞不高
[00:30.00]也许有一天我栖上枝头 却成为猎人的目标
[00:36.00]我飞上了青天才发现自己从此无依无靠
[00:43.00]每次到了夜深人静的时候我总是睡不着
[00:50.00]我怀疑是不是只有我的明天没有变得更好
[00:56.00]未来会怎样究竟有谁会知道
[01:03.00]幸福是否只是一种传说 我永远都找不到
[01:10.00]我是一只小小小小鸟 想要飞呀飞却飞也飞不高
[01:24.00]我寻寻觅觅寻寻觅觅一个温暖的怀抱
[01:29.00]这样的要求算不算太高
[01:37.00]我是一只小小小小鸟 想要飞呀飞却飞也飞不高
[01:51.00]我寻寻觅觅寻寻觅觅一个温暖的怀抱
[01:56.00]这样的要求算不算太高
[02:03.43]所有知道我的名字的人啊你们好不好
[02:27.33]所有知道我的名字的人啊你们好不好
[02:33.29]世界是如此的小 我们注定无处可逃
[02:40.20]当我 尽人情冷暖 当你决定为你了的理想燃烧
[02:46.67]生活的压力与生命的尊严哪一个重要
[02:54.36]我是一只小小小小鸟 想要飞呀飞却飞也飞不高
[03:07.10]我寻寻觅觅寻寻觅觅一个温暖的怀抱
[03:13.22]这样的要求算不算太高
[03:21.00]我是一只小小小小鸟 想要飞呀飞却飞也飞不高
[03:33.90]我寻寻觅觅寻寻觅觅一个温暖的怀抱
[03:40.31]这样的要求算不算太高
[03:46.17]所有知道我的名字的人啊你们好不好
[03:47.05]这样的要求算不算太高
[03:58.43]所有知道我的名字的人啊你们好不好
一个一个的修改删除,这多没劲啊...所以...
f=File.open('M0030002007.lrc') f.each do |line| puts line.gsub(/[\[\d:\.\]]/,'') end
评论
49 楼
fireflyman
2011-04-18
> Time.now.strftime("%Y-%m-1") "2011-04-1" > Time.now.strftime("%A %B %d or %a %e/%m") => "Monday April 11 or Mon 11/04"
48 楼
fireflyman
2011-04-15
简易字符转换
model ApplicationHelper def yes_no(bool) if bool == true "yes" else "no" end end end
47 楼
fireflyman
2011-04-02
config\initializers目录下建立一个custom_requires.rb,然后...
例如:G:\Program Files\ImageMagick-6.5.6-Q8
应填入-->(不支持空格)
Paperclip.options[:command_path] = "XX:/PROGRA~1/ImageMagick-6.5.6-Q8"
详细参考-->
Paperclip提示command is not recognized by the 'identify
http://hot88zh.iteye.com/blog/859238
46 楼
fireflyman
2011-04-02
下面两个相信是最常用的方法.....
logger.info("aaa--#{properties}-----------") <pre name="code" class="Ruby"><% logger.info("------#{@properties[2].inspect}----")%>
45 楼
fireflyman
2011-03-28
IE9出来了,又要弄个新的CSS hack。
body { color: green\9; /* IE8 */ *color: yellow; /* IE7 */ -color: orange; /* IE6 */ } body:not(:target) { color: red\9; /* IE9 */ } <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>css hack by 司徒正美</title> <style type="css/text"> body { color: green\9; /* IE8 */ *color: yellow; /* IE7 */ -color: orange; /* IE6 */ } body:not(:target) { color: red\9; /* IE9 */ } </style> </head> <body> </body> </html>
44 楼
fireflyman
2011-03-23
In Rails 2 the only way to add multiple validations to a field is through separate validate statements:
Rails 3 simplifies this process by adding a method called validates which is a “shortcut to all default validators”. Using the validates method your code will look like this:
validates_presence_of :title validates_length_of :title, :maximum => 30
Rails 3 simplifies this process by adding a method called validates which is a “shortcut to all default validators”. Using the validates method your code will look like this:
validates(:title, :presence => true, :length => {:maximum => 30})
43 楼
fireflyman
2011-03-01
Rails 預設是使用 ActiveRecord 下 query。
所以我們會寫出這種 code
不過當 category 與 post 是 many to many 的情況下,就會產生 join 的情況。所以 controller 有這種 query 會很痛。
改進方式:
在 Category 多寫兩個 method,用兩次 select 換掉 join。
速度會快上很多倍。
所以我們會寫出這種 code
@category.posts.published.limit(10)
不過當 category 與 post 是 many to many 的情況下,就會產生 join 的情況。所以 controller 有這種 query 會很痛。
Post Load (271.4ms) SELECT `posts`.* FROM `posts` INNER JOIN `post_categories` ON `posts`.id = `post_categories`.post_id WHERE ((aasm_state = ‘published’ and published_at <= '2011-02-26 17:54:19') AND ((`post_categories`.category_id = 1))) ORDER BY published_at DESC LIMIT 10
改進方式:
@category.all_posts.published.limit(10)
在 Category 多寫兩個 method,用兩次 select 換掉 join。
PostCategory Load (3.7ms) SELECT post_id FROM `post_categories` WHERE (`post_categories`.category_id = 1) Post Load (14.5ms) SELECT * FROM `posts` WHERE ((aasm_state = ‘published’ and published_at <= '2011-02-26 17:35:29') AND (`posts`.`id` IN (4,9,17,18,19,27,28,34,35,37,45,46,50,59,62,63,68,69,71,72,73,75,77,78,79,81,83,90,92,93,97,98,99...............) ORDER BY published_at DESC LIMIT 10
速度會快上很多倍。
42 楼
fireflyman
2011-01-26
快速排序
class Array def qsort return self if self.length <= 1 pivot = self.shift left, right = [],[] self.each { |ele| ele <= pivot ? left << ele : right << ele } left.qsort + [pivot] + right.qsort end end
41 楼
fireflyman
2011-01-25
Don´t confuse the right: validates_inclusion_of :published, :in => [true, false] with the wrong: validates_inclusion_of :published, :in => %w(true false) cause: %w(true false) == ["true", "false"]
40 楼
fireflyman
2011-01-25
[ "w", "x", "y", "z" ][-1] #=> "z"
39 楼
fireflyman
2011-01-25
"abc.,cde.,efg.,ghi".split(/.(,)/) => ["abc", ",", "cde", ",", "efg", ",", "ghi"] "abc.,cde.,efg.,ghi".split(/(.)(,)/) => ["abc", ".", ",", "cde", ".", ",", "efg", ".", ",", "ghi"] "abc.,cde.,efg.,ghi".split(/(.(,))/) => ["abc", ".,", ",", "cde", ".,", ",", "efg", ".,", ",", "ghi"] "abc.,cde.,efg.,ghi".split(/(.(,))/, 2) => ["abc", ".,", ",", "cde.,efg.,ghi"] "abc.,cde.,efg.,ghi".split(/(.(,))/, 3) => ["abc", ".,", ",", "cde", ".,", ",", "efg.,ghi"]
38 楼
fireflyman
2011-01-25
in the FirmsController @firm.people.update(params[:people].keys,params.values) in the View <% form_for(@firm) do |f| %> <%= f.error_messages %> <%= f.text_field :name %> <% @firm.people.each do |person| %> <% fields_for "people[]", person do |pf| %> <%= pf.text_field :name %> <% end %> <%= f.submit "Save" %> <% end %>
37 楼
fireflyman
2011-01-25
检查数字是否是素数?
def prime? ('1' * self) !~ /^1?$|^(11+?)\1+$/ end irb(main):004:0> 10.prime? => false irb(main):005:0> 11.prime? => true
36 楼
fireflyman
2011-01-25
数组转散列
array = [['A', 'a'], ['B', 'b'], ['C', 'c']] hash = array.inject({}) do |memo, values| memo[values.first] = values.last memo end hash # => {'A' => 'a', 'B' => 'b', 'C' => 'c'}
35 楼
fireflyman
2011-01-25
date_select("user", "birthday", :start_year => 1940, :end_year => Date.current.year - 13)
34 楼
fireflyman
2011-01-25
<% remote_form_for "comment",:update => "form" do |f| %> # your form here <% end %>
或
<% remote_form_for "comment", :update => {:success => "form", :failure => "errors"} do |f| %> # your form here <% end %>
33 楼
fireflyman
2011-01-25
Following the similar egzample by autonomous, here's a simpler version when you just need to write a flexible helper method that takes a block.
For example, suppose you have a method that renders a tree:
You can use it in your view, eg:
that would return for egzample:
Testing concat
To test such helper methods, use the following pattern (a utility method added to your Rspec/unit test suite:
and test like this (RSpec example):
For example, suppose you have a method that renders a tree:
def render_tree(ary, &block) concat("<ul>", block.binding) for elem in ary concat("<li>", block.binding) yield elem concat("</li>", block.binding) end concat("</ul>", block.binding) end
You can use it in your view, eg:
<% render_tree(@objects) do |elem| -%> <%= elem.title -%> <%= link_to 'delete', elem -%> <% end -%>
that would return for egzample:
<ul> <li> Test title <a href="delete">/elems/1</a> </li> </ul>
Testing concat
To test such helper methods, use the following pattern (a utility method added to your Rspec/unit test suite:
def render_for(root, options = {}) _erbout = '' render_tree(root, options) do |node| _erbout.concat(node.title) end _erbout end
and test like this (RSpec example):
it "should return abc" do render_for(object).should == 'abc' end
32 楼
fireflyman
2011-01-24
validates_format_of :uri, :with => URI.regexp(['http'])
31 楼
fireflyman
2011-01-23
Link to Unimplemented
# public/javascripts/application.js function unimplemented() { alert("NOTICE\n\nThis feature is not implemented yet. Please check back again soon!"); } This allows us to do the following: <a href="javascript:unimplemented();">link text</a> # app/helpers/application_helper.rb def link_to_unimplemented( link_text, *args ) link_to_function( link_text, 'unimplemented()', *args) end Now, we’re able to use link_to_unimplemented and pass any arguments that you’d pass to the default link_to view helper. <%= link_to_unimplemented( 'link text', { :class => 'link_class_name' } ) -%>
30 楼
fireflyman
2011-01-23
<div id="footer"> © Copyright <%= current_year -%>. All Rights Reserved. </div>
# add to application_helper.rb module ApplicationHelper def current_year Time.now.strftime('%Y') end end
发表评论
-
快闪行动-->为你的项目添加标签模块
2011-04-23 16:44 1130在开始之前,还是要不厌其烦的说说,那些不必要写的你自己搞把,反 ... -
Paperclip在Windows下的那些Po事
2011-04-02 04:22 12681.Paperclip提示command is not rec ... -
FireBug实用指南
2011-03-28 00:14 1322古语有云:工欲善其事必先利其器.对于Web开发人员来说, ... -
在或不在
2011-02-13 23:58 0我在我的路上停止了脚步,为的是走一条新的路...没有人明白我的 ... -
验证码生成插件simple_captcha
2011-01-12 23:37 1862插件地址:https://github.com/eshopwo ... -
关于Mar's shoe的创意思考
2011-01-12 00:52 987在昨天我的一个伙 ... -
我是rails插件控
2010-12-01 03:01 0有些问题总是有点疑惑,既然能够用插件解决,为啥要自己写呢?反正 ... -
豆瓣“我说”功能的rails简单实现
2010-11-30 23:07 011111 -
用rails开发新版的起点中文网
2010-11-30 23:06 011111 -
用rails实现简单邮件发送测试
2010-11-02 17:53 1431我的环境是ruby1.8.7, rails ... -
工作中遇到的Aajx
2010-10-30 10:22 01.ObjectRange $A($R(1,5)).join( ... -
后台订单处理提醒功能
2010-10-26 17:31 01.参考豆瓣提醒 2. 用户<%= link_to&qu ... -
工作遇到的图片问题
2010-10-26 11:09 0<% record = shirt_window %&g ... -
工作中遇到的JS
2010-10-26 10:17 01.getElementById() 方法可返回对拥有指定 I ... -
页面代码
2010-10-25 13:08 0<% record = shirt_window %&g ... -
工作中遇到的CSS
2010-10-24 20:13 01.cursor 属性规定要显示的光标的类型(形状). 引用 ... -
工作小记
2010-10-19 18:50 01.svn commit 提交要注意别把别人的代码冲走了.. ... -
問答頻道模塊開發
2010-10-12 09:22 0直接參考JE的問道頻道.... -
草稿箱的崛起...
2010-09-30 16:51 0你懂个P啊... -
我该怎么折腾(初级火球术)
2010-09-30 03:17 8431.阅读,你需要不断的阅读,任何时候都不应该放弃这个准则..一 ...
相关推荐
ruby on rails 书全集(10余本经典著作PDF版)
ruby_ship, 便携式 MRI ruby 环境和工具集 ruby-船 可以在任何平台上移植便携式 MRI ruby 环境,任何版本的MRI ruby ! 不需要在计算机上安装 ruby 即可使用它 !ruby的目标是拥有一个包含 ruby的单独文件夹,它在...
ruby代码ruby代码ruby代码ruby代码ruby代码ruby代码ruby代码ruby代码
Ruby是一种纯粹的面向对象编程语言。它由日本的松本行弘(まつもとゆきひろ/Yukihiro Matsumoto)创建于1993年。 您可以在 www.ruby-lang.org 的 Ruby 邮件列表上找到松本行弘(まつもとゆきひろ/Yukihiro Matsumoto...
这是linux版本下的ruby2.1.5版本,亲测可用,现在最新的版本
ruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ...
ruby 入门 中文 合集
Redis安装遇到错误解决方案Error installing redis: redis requires Ruby version >= 2.3.0. 先安装rvm,再把ruby版本提升至2.3.0
《Ruby完全自学手册》是一本完全覆盖Ruby和Ruby on Rails的完全自学手册。《Ruby完全自学手册》的特色是由浅入深、循序渐进,注重理论和实践的结合。虽然定位为入门手册,但是依然涉及许多高级技术和应用,覆盖到的...
ruby2ruby 提供一些用来根据 RubyParser 兼容的 Sexps 轻松生成纯 Ruby 代码的方法。可在 Ruby 中轻松实现动态语言处理。 标签:ruby2ruby
Ruby编程,Ruby编程,Ruby编程,Ruby编程,Ruby编程,
该资源包包括在Linux安装Ruby on Rails所需的包,以及安装步骤文档
ruby源代码 ruby源代码 ruby源代码 ruby源代码2
Boxtech数据由运输公司,租赁公司和其他集装箱运营商提供支持,提供比集装箱门上更多的信息,并在租赁集装箱的情况下标识集装箱的当前运营商。 完整的细节可以上BIC是一个中立的非营利性国际组织,成立于1933年,由...
ruby源代码 ruby源代码 ruby源代码 ruby源代码4
Ruby,一种为简单快捷的面向对象编程(面向对象程序设计)而创的脚本语言,在20世纪90年代由日本人松本行弘(Yukihiro Matsumoto)开发,遵守GPL协议和Ruby License。它的灵感与特性来自于 Perl、Smalltalk、Eiffel、...
Ruby语言教程合集(2本).zip Ruby教程 Rails Web开发框架
推荐使用macOS或各种发行版本的Linux作为运行环境,尽管Windows下也可以进行Ruby开发,但环境配置会比较复杂。在macOS或Linux下,可以通过包管理工具来安装Ruby。安装完成后,可以通过在命令行中输入ruby -v来检查...
ruby笔记1ruby笔记1ruby笔记1ruby笔记1ruby笔记1ruby笔记1