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}) %>就能取出数据库中对应的数据
相关文档:
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 ......
从今天起不再浪费时间,开始走向自动化测试这条光明的道路,并以搭建一个自动化测试平台为目标,并这个过程一点点的记录下来和大家分享
首先,是ruby环境的搭建
(1)到ruby的官网:http://www.ruby-lang.org/en/下载 ruby安装程序;
PS :选择 ruby on windows,我下载的是Ruby 1.8.6 One ......
在使用中ruby的过程中难免会遇到提高性能的问题,由此便想起了ruby线程。但是我在使用中却发现ruby的线程却不能提高性能。我写了以下代码,做了些简单测试。
代码
# -*- coding: GB2312 -*-
require 'date'
# 使用线程,线程的处理代码里没有sleep
def have_thread_no_sleep
p Time.now
thread1 = Thread.new do
......
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 ......
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 ......