易截截图软件、单文件、免安装、纯绿色、仅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}) %>就能取出数据库中对应的数据


相关文档:

ruby的Excel操作

require 'win32ole'
excel = WIN32OLE::new('excel.Application')
workbook = excel.Workbooks.Open('E:\RubyApp\bmk.xls')
worksheet = workbook.Worksheets(1) #get hold of the first worksheet
worksheet.Select #bring it to the front -need sometimes to run macros, not for working with a worksheet from ru ......

升级到snow leopard后ruby的问题

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 ......

交互式 Ruby Shell irb

irb 是从命令行运行的
irb 的命令行选项(摘自 Porgramming Ruby 第二版)
-f
禁止读取~/.irbrc Suppress reading ~/.irbrc.
-m
数学模式(支持分数和矩阵) Math mode (fraction and matrix support is available).
-d
设置#DEBUG为true(同ruby -d一样)  Set $DEBUG to true (same as ``ruby -d'').
-r lo ......

linux(ubuntu)下ruby开发环境搭建

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 ......

Ruby 一步步安装


http://www.gayathri-frenzy.com/technology/ruby-on-rails
I kept thinking for a while on what do I have next in the store
Here we go “Ruby on Rails”
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby Programming language.Ruby is a ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号