易截截图软件、单文件、免安装、纯绿色、仅160KB

ruby on rails 解决multiple select 存储和update

操作系统ubuntu,开发工具netbeans
vendor数据库表有字段service_category varchar(100)
<% form_for :vendor, @vendor, :url => sellers_path do |f| %>
  <%= f.select(:service_category,
                   ["Painting","Plumbing","Decor"], {}, {:multiple => true, :size => 3}) %>
  <%= f.submit "Register"%>
<% end %>
url 指定到哪个control  action,用的是rails rest技术
但是存入数据库表的是--\painting --之类的字符串,不符合要求
所以在vendor model中加入
def service_category=(values)
    if !values.nil?
          write_attribute('service_category', values.join(','))
    end
 end
 def service_category
    if !read_attribute('service_category').nil?
          read_attribute('service_category').split(',')
    end
 end
存入数据库中的是painting,plumbing
在update action中@vendor = Vendor.find(id)
在update 页面<%= f.select(:service_category,
                   ["Painting","Plumbing","Decor"], {}, {:multiple => true, :size => 3}) %>就能取出数据库中对应的数据


相关文档:

rails on ruby exmaples depot

1.install ruby
    download from http://www.ruby-lang.org/en/news/2009/12/07/ruby-1-9-1-p376-is-released/
2.install rails
   ruby gem install rails --include-dependencies
3.install mysql
   download from http://sourceforge.net
   ruby gem install&nb ......

Ruby Shoes 的鼠标事件

因为一次偶然的机会接触了Ruby语言。然后下载了Ruby Shoes工具。
发现Ruby还是蛮有趣的。
花了一段时间熟悉了它的语法。
下面来试试它的鼠标功能。
Shoes.app do
  #图片初始化
  @img = image "http://www.google.cn/intl/zh-CN/images/logo_cn.gif"
  #图片关于鼠标的调用
 & ......

ruby 线程的性能测试

在使用中ruby的过程中难免会遇到提高性能的问题,由此便想起了ruby线程。但是我在使用中却发现ruby的线程却不能提高性能。我写了以下代码,做了些简单测试。
代码
# -*- coding: GB2312 -*-
require 'date'
# 使用线程,线程的处理代码里没有sleep
def have_thread_no_sleep
p Time.now
thread1 = Thread.new do
......

设计模式 观察者模式实现例子(ruby)

ruby中自带实现观察者模式的类observer。可以利用它来实现观察者模式。
代码例子:
# -*- coding: GB2312 -*-
require 'observer'
# 观察者模式(ruby)的使用例子
# 被观察者P
class PObservable
include Observable
end
# 观察者A
class AObserver
# update方法名是必须的要有的
def update(arg)
puts "AO ......

ruby:查看版本,命令行运行程序


原文连接: http://hi.baidu.com/%B7%CF%B2%C5%CB%FB%B8%E7/blog/item/09c19411244152daf7039ec4.html
通过命令行查看ruby版本信息:
ruby -v
命令行运行程序:
方法1.
ruby -e 'print "hello ruby"'
-e 表示将后面的一行作为ruby程序
print 是ruby的一个内置函数
方法2.交互编译环境
irb (命令行输入后, ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号