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}) %>就能取出数据库中对应的数据
相关文档:
在使用中ruby的过程中难免会遇到提高性能的问题,由此便想起了ruby线程。但是我在使用中却发现ruby的线程却不能提高性能。我写了以下代码,做了些简单测试。
代码
# -*- coding: GB2312 -*-
require 'date'
# 使用线程,线程的处理代码里没有sleep
def have_thread_no_sleep
p Time.now
thread1 = Thread.new do
......
ruby中自带实现观察者模式的类observer。可以利用它来实现观察者模式。
代码例子:
# -*- coding: GB2312 -*-
require 'observer'
# 观察者模式(ruby)的使用例子
# 被观察者P
class PObservable
include Observable
end
# 观察者A
class AObserver
# update方法名是必须的要有的
def update(arg)
puts "AO ......
1. ruby已成为1.87
2. 必须先安装安装光盘里的新的xcode,在"optional"目录里
3. 可能需要重新安装macport
http://trac.macports.org/wiki/Migration
4. 或者升级macport
http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard
$ sudo port selfupdate
$ sudo port sync
$ sudo port upgrade --force insta ......
env setup
linux(ubuntu)下ruby开发环境搭建,包括一些常见问题解决
注意,本文只是我在搭建ruby学习环境时的一些笔记,因为是用gedit编辑的,所以格式化不是很好,另外,只是备忘而已。
2010.1.19
1. install ruby
$ tar xzf ruby-1.8.7-p248.tar.gz
$ mv ruby-1.8.7-p248 ruby187
$ cd ruby187/
$ ./configure
......