$ gem uninstall rbtree
You have requested to uninstall the gem:
rbtree-0.4.1
drip-0.0.2 depends on rbtree (>= 0)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN] n
ERROR: While executing gem ... (Gem::DependencyRemovalException)
Uninstallation aborted due to dependent gem(s)
六、 查看gem文档
ri 命令可以用于查看gem的文档。或者运行 gem server 通过浏览器查看
七、 Fetching and Unpacking Gems
如果你仅仅想获取并查看一个gem的内容,可以通过fetch和unpack命令来实现:
12345678910111213141516
╭─# ivan@ubuntu in ~/private/temp ‹ruby-1.8.7@rails304›
╰─$ gem fetch json
Fetching: json-1.1.5-x86-linux.gem (100%)
Downloaded json-1.1.5-x86-linux
╭─# ivan@ubuntu in ~/private/temp ‹ruby-1.8.7@rails304›
╰─$ ls
json-1.1.5-x86-linux.gem
╭─# ivan@ubuntu in ~/private/temp ‹ruby-1.8.7@rails304›
╰─$ gem unpack json-1.1.5-x86-linux.gem
Unpacked gem: '/home/ivan/private/temp/json-1.1.5-x86-linux'
╭─# ivan@ubuntu in ~/private/temp ‹ruby-1.8.7@rails304›
╰─$ ls
json-1.1.5-x86-linux json-1.1.5-x86-linux.gem
# coding: utf-8
module MyGem
module MyHelper
def my_helper
time = DateTime.parse(Time.now.to_s).strftime('%H:%M:%S').to_s
date = DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d').to_s
html = []
html << '<div id="mydiv">'
html << '<div id="time">' + time + '</div>'
html << '<div id="date">' + date + '</div>'
html << '</div>'
raw html.join("\n")
end
end
end
(0.1ms) begin transaction
/home/ivan/work/temp/packagetest/app/models/material_type.rb:7: warning: multiple values for a block parameter (0 for 1)
from /home/ivan/.rvm/gems/ruby-1.8.7-p371@rails304/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192
(0.4ms) insert into material_types(id,name,code,parent_id,created_at,updated_at) values ('40', '40_name','code', 40, 'Fri Nov 29 11:08:54 +0800 2013', 'Fri Nov 29 11:08:54 +0800 2013')
(317.6ms) commit transaction
(0.1ms) begin transaction
/home/ivan/work/temp/packagetest/app/models/material_type.rb:7: warning: multiple values for a block parameter (0 for 1)
from /home/ivan/.rvm/gems/ruby-1.8.7-p371@rails304/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192
(0.4ms) insert into material_types(id,name,code,parent_id,created_at,updated_at) values ('41', '41_name','code', 41, 'Fri Nov 29 11:08:54 +0800 2013', 'Fri Nov 29 11:08:54 +0800 2013')
(307.8ms) commit transaction
sql="insert into option (release_time, package_type, id, db_name, db_id) ..."@db.executesqlsql="select * from posts where title=? and name=? "@db.execute(sql,'标题','名称')
4 遍历结果集
123
@db.execute(sql,'标题','名称').eachdo|post|#...end
注意:如果没有找到数据会抛出异常,需要自行处理一下。
5 在单个事务中批量操作
12345
@db.transaction100.timesdo|i|@db.execute("insert into post where name = 'name_#{i}' ")end@db.commit
或者
12345
@db.transactiondo100.timesdo|i|@db.execute("insert into post where name = 'name_#{i}' ")endend