<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Neo&#039;s notes &#187; Ruby On Rails</title>
	<atom:link href="http://www.neocanable.com/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.neocanable.com</link>
	<description>记录一些琐碎的技术问题&#124;发泄胸中的各种不满</description>
	<lastBuildDate>Tue, 17 Jan 2012 05:37:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>thinking-sphinx的排序</title>
		<link>http://www.neocanable.com/thinking-sphinx-sor/</link>
		<comments>http://www.neocanable.com/thinking-sphinx-sor/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 13:59:20 +0000</pubDate>
		<dc:creator>Neo</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://www.neocanable.com/?p=635</guid>
		<description><![CDATA[sphinx本身支持datetime、integer、float、string等类型的排序，但是thinking-sphinx在定义索引的时候给人造成的误区简直让人想骂娘！ indexes :accepted_id, :sortable =&#62; true 这行是假象，默认是用字符串排序，即使accepted_id 是整型的！ 正确写法 &#160;has :accepted_id, :type =&#62; :integer 这里声明accepted_id是个属性，支持integer类型的排序和索引！ 唉，看文档是王道啊]]></description>
			<content:encoded><![CDATA[<p>sphinx本身支持datetime、integer、float、string等类型的排序，但是thinking-sphinx在定义索引的时候给人造成的误区简直让人想骂娘！</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">indexes <span style="color:#ff3333; font-weight:bold;">:accepted_id</span>, <span style="color:#ff3333; font-weight:bold;">:sortable</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span></div></div>
<p>这行是假象，默认是用字符串排序，即使accepted_id 是整型的！</p>
<p>正确写法</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;has <span style="color:#ff3333; font-weight:bold;">:accepted_id</span>, <span style="color:#ff3333; font-weight:bold;">:type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> :<span style="color:#CC0066; font-weight:bold;">integer</span></div></div>
<p>这里声明accepted_id是个属性，支持integer类型的排序和索引！</p>
<p>唉，看文档是王道啊</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neocanable.com/thinking-sphinx-sor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>resque使用</title>
		<link>http://www.neocanable.com/resque-usag/</link>
		<comments>http://www.neocanable.com/resque-usag/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 17:03:38 +0000</pubDate>
		<dc:creator>Neo</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://www.neocanable.com/?p=607</guid>
		<description><![CDATA[resque 是ruby和redis结合做的一个消息队列，稳定性和成熟性还有待考察，但是，用起来真是很爽 安装 gem install resque --no-ri --no-rdoc 或者rails3直接写到Gemfile里面，然后bundle install 在rails或者ruby 的app里导入项目，然后require到resque和job文件 执行rake resque:work QUEUE=&#8217;*'或者针对个别的job单独启动，用起来太舒服了！！！！！！ 不能忘了配置redis:) 案例 在app目录下建立jobs目录 在RAILS_ROOT/config/initializers/resque.rb中加入 &#160;Dir&#91;&#34;#{Rails.root}/app/jobs/*.rb&#34;&#93;.each &#123; &#124;file&#124; require file &#125; 建立一个可执行的ruby文件job1.rb class Job1 &#160; @queue = :job1 &#160; def self.perform&#40;arg&#41; &#160; &#160; &#160;p &#34;your code here!!!&#34; &#160; end end 执行 rake resque:work QUEUE='*' 可以看到&#8221;your code here!!!&#8221; 类的字符串输出]]></description>
			<content:encoded><![CDATA[<p>resque 是ruby和redis结合做的一个消息队列，稳定性和成熟性还有待考察，但是，用起来真是很爽</p>
<p>安装</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gem install resque <span style="color:#006600; font-weight:bold;">--</span>no<span style="color:#006600; font-weight:bold;">-</span>ri <span style="color:#006600; font-weight:bold;">--</span>no<span style="color:#006600; font-weight:bold;">-</span>rdoc</div></div>
<p>或者rails3直接写到Gemfile里面，然后bundle install</p>
<p>在rails或者ruby 的app里导入项目，然后require到resque和job文件</p>
<p>执行rake resque:work QUEUE=&#8217;*'或者针对个别的job单独启动，用起来太舒服了！！！！！！<br />
不能忘了配置redis:)</p>
<p>案例</p>
<p>在app目录下建立jobs目录<br />
在RAILS_ROOT/config/initializers/resque.rb中加入</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;#{Rails.root}/app/jobs/*.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">require</span> file <span style="color:#006600; font-weight:bold;">&#125;</span></div></div>
<p>建立一个可执行的ruby文件job1.rb</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Job1<br />
&nbsp; <span style="color:#0066ff; font-weight:bold;">@queue</span> = <span style="color:#ff3333; font-weight:bold;">:job1</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">perform</span><span style="color:#006600; font-weight:bold;">&#40;</span>arg<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#996600;">&quot;your code here!!!&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>执行</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rake resque:work QUEUE=<span style="color:#996600;">'*'</span></div></div>
<p>可以看到&#8221;your code here!!!&#8221; 类的字符串输出</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neocanable.com/resque-usag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rails devise hook</title>
		<link>http://www.neocanable.com/rails-devise-hook/</link>
		<comments>http://www.neocanable.com/rails-devise-hook/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 18:03:46 +0000</pubDate>
		<dc:creator>Neo</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://www.neocanable.com/?p=544</guid>
		<description><![CDATA[1. 登录后的 Warden::Manager.before_logout do &#124;user,auth,opts&#124; &#160; user.update_attribute&#40;:authentication_token, false&#41; &#160; auth.cookies.delete&#40;'remember_token'&#41; end 2.验证后的，在remember的时候可以向cookie里面塞入一个token Warden::Manager.after_authentication do &#124;record, auth, options&#124; &#160; &#160; scope = options&#91;:scope&#93; &#160; &#160; remember_me = auth.params&#91;scope&#93;.try&#40;:fetch, :remember_me, nil&#41; &#160; &#160; if Devise::TRUE_VALUES.include?&#40;remember_me&#41; &#38;&#38; record.respond_to?&#40;:remember_me!&#41; &#160; &#160; record.remember_me! &#160; &#160; auth.cookies&#91;'remember_token'&#93; = &#123; &#160; &#160; &#160; :value =&#62; record.authentication_token, &#160; &#160; &#160; :expires =&#62; record.remember_expires_at [...]]]></description>
			<content:encoded><![CDATA[<p>1. 登录后的</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#6666ff; font-weight:bold;">Warden::Manager</span>.<span style="color:#9900CC;">before_logout</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>user,auth,opts<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; user.<span style="color:#9900CC;">update_attribute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:authentication_token</span>, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; auth.<span style="color:#9900CC;">cookies</span>.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'remember_token'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>2.验证后的，在remember的时候可以向cookie里面塞入一个token</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#6666ff; font-weight:bold;">Warden::Manager</span>.<span style="color:#9900CC;">after_authentication</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>record, auth, options<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; scope = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:scope</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; remember_me = auth.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span>scope<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">try</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:fetch</span>, <span style="color:#ff3333; font-weight:bold;">:remember_me</span>, <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#6666ff; font-weight:bold;">Devise::TRUE_VALUES</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>remember_me<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> record.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:remember_me</span>!<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; record.<span style="color:#9900CC;">remember_me</span>!<br />
&nbsp; &nbsp; auth.<span style="color:#9900CC;">cookies</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'remember_token'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:value</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> record.<span style="color:#9900CC;">authentication_token</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:expires</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> record.<span style="color:#9900CC;">remember_expires_at</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.neocanable.com/rails-devise-hook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rails3.1－invalid multibyte char (US-ASCII) (SyntaxError)</title>
		<link>http://www.neocanable.com/rails3-1-invalid-multibyte-char/</link>
		<comments>http://www.neocanable.com/rails3-1-invalid-multibyte-char/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 13:47:54 +0000</pubDate>
		<dc:creator>Neo</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://www.neocanable.com/?p=354</guid>
		<description><![CDATA[# Load the rails application # encoding: utf-8 require File.expand_path&#40;'../application', __FILE__&#41; # Initialize the rails application Review::Application.initialize! WillPaginate::ViewHelpers.pagination_options&#91;:previous_label&#93; = '&#38;laquo;上一页' WillPaginate::ViewHelpers.pagination_options&#91;:next_label&#93; = '下一页&#38;raquo;' rails3.1必须用ruby1.9去跑，然而1.9的编码处置非常2 必须文件头加上encoding才能顺利运行，否则就出现invalid multibyte char (US-ASCII) (SyntaxError) 当然，上面的配置在3.1中必然会报错，文件头也就是文件的第一行（new shit！！！），应该将# Load the rails application删掉,将encoding: utf-8放在第一行，fckkkkkkkkkkkkkk]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;"># Load the rails application</span><br />
<span style="color:#008000; font-style:italic;"># encoding: utf-8</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'../application'</span>, <span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># Initialize the rails application</span><br />
<span style="color:#6666ff; font-weight:bold;">Review::Application</span>.<span style="color:#9900CC;">initialize</span>!<br />
<br />
<span style="color:#6666ff; font-weight:bold;">WillPaginate::ViewHelpers</span>.<span style="color:#9900CC;">pagination_options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:previous_label</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">'&amp;laquo;上一页'</span><br />
<span style="color:#6666ff; font-weight:bold;">WillPaginate::ViewHelpers</span>.<span style="color:#9900CC;">pagination_options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:next_label</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">'下一页&amp;raquo;'</span></div></div>
<p>rails3.1必须用ruby1.9去跑，然而1.9的编码处置非常2</p>
<p>必须文件<strong>头</strong>加上encoding才能顺利运行，否则就出现invalid multibyte char (US-ASCII) (SyntaxError)</p>
<p>当然，上面的配置在3.1中必然会报错，<strong>文件头也就是文件的第一行（new shit！！！）</strong>，应该将# Load the rails application删掉,将encoding: utf-8放在第一行，fckkkkkkkkkkkkkk</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neocanable.com/rails3-1-invalid-multibyte-char/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>rails migration 独立使用</title>
		<link>http://www.neocanable.com/just-use-rails-migration/</link>
		<comments>http://www.neocanable.com/just-use-rails-migration/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 11:51:23 +0000</pubDate>
		<dc:creator>Neo</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.neocanable.com/?p=267</guid>
		<description><![CDATA[将migration的rake任务从rails里面抠出来!!! DB_ENV = &#34;development&#34; ROOT = File.expand_path&#40;File.dirname&#40;__FILE__&#41;&#41; database_config = File.expand_path&#40;File.dirname&#40;__FILE__&#41; + &#34;/database.yml&#34;&#41; log_path = File.expand_path&#40;File.dirname&#40;__FILE__&#41; + &#34;/migration.log&#34;&#41; namespace :db do &#160; task :environment =&#62; :load_config do &#160; &#160; ActiveRecord::Base.establish_connection&#40;YAML.load&#40;File.new&#40;database_config&#41;&#41;&#91;DB_ENV&#93;&#41; &#160; &#160; ActiveRecord::Base.logger = Logger.new&#40;log_path&#41; &#160; end &#160; task :load_config do &#160; &#160; require 'active_record' &#160; &#160; ActiveRecord::Base.configurations = YAML.load&#40;File.new&#40;database_config&#41;&#41; &#160; end &#160; desc '创建数据库' &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>将migration的rake任务从rails里面抠出来!!!</strong></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DB_ENV = <span style="color:#996600;">&quot;development&quot;</span><br />
ROOT = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
database_config = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/database.yml&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
log_path = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/migration.log&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; task <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:load_config</span> <span style="color:#9966CC; font-weight:bold;">do</span> <br />
&nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">establish_connection</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">YAML</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>database_config<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>DB_ENV<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">logger</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>log_path<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; task <span style="color:#ff3333; font-weight:bold;">:load_config</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'active_record'</span><br />
&nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">configurations</span> = <span style="color:#CC00FF; font-weight:bold;">YAML</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>database_config<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; desc <span style="color:#996600;">'创建数据库'</span><br />
&nbsp; task <span style="color:#ff3333; font-weight:bold;">:create</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:load_config</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; create_database<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">configurations</span><span style="color:#006600; font-weight:bold;">&#91;</span>DB_ENV<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; desc <span style="color:#996600;">'删除数据库'</span><br />
&nbsp; task <span style="color:#ff3333; font-weight:bold;">:drop</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:load_config</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; config = <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">configurations</span><span style="color:#006600; font-weight:bold;">&#91;</span>DB_ENV<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; drop_database<span style="color:#006600; font-weight:bold;">&#40;</span>config<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e<br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Couldn't drop #{config['database']} : #{e.inspect}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; desc <span style="color:#996600;">&quot;迁移数据库&quot;</span><br />
&nbsp; task <span style="color:#ff3333; font-weight:bold;">:migrate</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>.<span style="color:#9900CC;">verbose</span> = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;VERBOSE&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;VERBOSE&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">&quot;true&quot;</span> : <span style="color:#0000FF; font-weight:bold;">true</span><br />
&nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migrator</span>.<span style="color:#9900CC;">migrate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;migrate&quot;</span>, ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;VERSION&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;VERSION&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span> : <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">Rake::Task</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;db:schema:dump&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">invoke</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">schema_format</span> == <span style="color:#ff3333; font-weight:bold;">:ruby</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<br />
&nbsp; desc <span style="color:#996600;">'重置数据库'</span><br />
&nbsp; task <span style="color:#ff3333; font-weight:bold;">:reset</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'db:drop'</span>, <span style="color:#996600;">'db:setup'</span> <span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; desc <span style="color:#996600;">'重置数据库并且执行seed'</span><br />
&nbsp; task <span style="color:#ff3333; font-weight:bold;">:setup</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'db:create'</span>, <span style="color:#996600;">'db:schema:load'</span>, <span style="color:#996600;">'db:seed'</span> <span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; desc <span style="color:#996600;">'执行 seed.rb'</span><br />
&nbsp; task <span style="color:#ff3333; font-weight:bold;">:seed</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; seed_file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/seed.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span>seed_file<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exist</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>seed_file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; namespace <span style="color:#ff3333; font-weight:bold;">:schema</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; desc <span style="color:#996600;">&quot;创建schema.rb&quot;</span><br />
&nbsp; &nbsp; task <span style="color:#ff3333; font-weight:bold;">:dump</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'active_record/schema_dumper'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/schema.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;wb&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::SchemaDumper</span>.<span style="color:#9900CC;">dump</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>, file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">Rake::Task</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;db:schema:dump&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">reenable</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; desc <span style="color:#996600;">&quot;load schema.rb到数据库&quot;</span><br />
&nbsp; &nbsp; task :<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/schema.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; abort <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span>error<span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; namespace <span style="color:#ff3333; font-weight:bold;">:structure</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; desc <span style="color:#996600;">&quot;导出sql文件&quot;</span><br />
&nbsp; &nbsp; task <span style="color:#ff3333; font-weight:bold;">:dump</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; abcs = <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">configurations</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">case</span> abcs<span style="color:#006600; font-weight:bold;">&#91;</span>DB_ENV<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;adapter&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;mysql&quot;</span>, <span style="color:#996600;">&quot;oci&quot;</span>, <span style="color:#996600;">&quot;oracle&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">establish_connection</span><span style="color:#006600; font-weight:bold;">&#40;</span>abcs<span style="color:#006600; font-weight:bold;">&#91;</span>DB_ENV<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>ROOT <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/#{DB_ENV}_structure.sql&quot;</span>, <span style="color:#996600;">&quot;wb&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">structure_dump</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;不支持数据库类型： '#{abcs[&quot;</span>test<span style="color:#996600;">&quot;][&quot;</span>adapter<span style="color:#996600;">&quot;]}'&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">supports_migrations</span>?<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>ROOT <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/#{DB_ENV}_structure.sql&quot;</span>, <span style="color:#996600;">&quot;a&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">dump_schema_information</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">def</span> drop_database<span style="color:#006600; font-weight:bold;">&#40;</span>config<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">case</span> config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'adapter'</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'mysql'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">establish_connection</span><span style="color:#006600; font-weight:bold;">&#40;</span>config<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">drop_database</span> config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'database'</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#ff6633; font-weight:bold;">$stderr</span>.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;删除数据库出错&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">def</span> create_database<span style="color:#006600; font-weight:bold;">&#40;</span>config<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">case</span> config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'adapter'</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'mysql'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@charset</span> &nbsp; = <span style="color:#996600;">'utf8'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@collation</span> = <span style="color:#996600;">'utf8_unicode_ci'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">establish_connection</span><span style="color:#006600; font-weight:bold;">&#40;</span>config.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'database'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">create_database</span><span style="color:#006600; font-weight:bold;">&#40;</span>config<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'database'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:charset</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>@charset<span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:collation</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>@collation<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">establish_connection</span><span style="color:#006600; font-weight:bold;">&#40;</span>config<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">rescue</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff6633; font-weight:bold;">$stderr</span>.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;创建数据库出错&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#ff6633; font-weight:bold;">$stderr</span>.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;擦,就支持mysql&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>目录结构</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<br />
<span style="color: #000000; font-weight: bold;">|</span>-- Rakefile<br />
<span style="color: #000000; font-weight: bold;">|</span>-- database.yml<br />
<span style="color: #000000; font-weight: bold;">|</span>-- migrate<br />
<span style="color: #000000; font-weight: bold;">|</span> &nbsp; <span style="color: #000000; font-weight: bold;">`</span>-- <span style="color: #000000;">20110124014258</span>_old_version.rb<br />
<span style="color: #000000; font-weight: bold;">|</span> &nbsp; <span style="color: #000000; font-weight: bold;">`</span>-- <span style="color: #000000;">20110124014259</span>_old_version.rb<br />
<span style="color: #000000; font-weight: bold;">`</span>-- schema.rb</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.neocanable.com/just-use-rails-migration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>体验rails-3 ActiveModel</title>
		<link>http://www.neocanable.com/rails3-activemodel/</link>
		<comments>http://www.neocanable.com/rails3-activemodel/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 13:00:09 +0000</pubDate>
		<dc:creator>Neo</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://www.neocanable.com/?p=19</guid>
		<description><![CDATA[active_model是rails3新添加的一个模块，主要功能是让ruby对象都能像active_record一样使用 1.validation &#160;class User &#160; &#160;include ActiveModel::Validations &#160; &#160;attr_accessor :first_name,:last_name &#160; &#160; &#160;validates_presence_of :first_name,:last_name &#160; &#160;end &#160; &#160;p1 = User.new &#160; &#160;p1.errors &#160;# =&#62; &#60;OrderedHash {:first_name=&#62;[&#34;can't be blank&#34;], &#160; &#160; &#160; &#160; &#160; &#160; #:last_name=&#62;[&#34;can't be blank&#34;]}&#62; &#160;p1.valid? &#160;# =&#62; false 也可以这样使用 # models/user_validator.rb class UserValidator &#60; ActiveModel::Validator &#160; def validate&#40;record&#41; &#160; &#160; record.errors&#91;:base&#93; = [...]]]></description>
			<content:encoded><![CDATA[<p>active_model是rails3新添加的一个模块，主要功能是让ruby对象都能像active_record一样使用</p>
<p><strong>1.validation</strong></p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color:#9966CC; font-weight:bold;">class</span> User<br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::Validations</span><br />
&nbsp; &nbsp;attr_accessor <span style="color:#ff3333; font-weight:bold;">:first_name</span>,:last_name<br />
&nbsp;<br />
&nbsp; &nbsp;validates_presence_of <span style="color:#ff3333; font-weight:bold;">:first_name</span>,:last_name<br />
&nbsp;<br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp;p1 = User.<span style="color:#9900CC;">new</span><br />
&nbsp;<br />
&nbsp;p1.<span style="color:#9900CC;">errors</span> &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; &lt;OrderedHash {:first_name=&gt;[&quot;can't be blank&quot;], </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#:last_name=&gt;[&quot;can't be blank&quot;]}&gt;</span><br />
&nbsp;p1.<span style="color:#9900CC;">valid</span>? &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; false</span></div></div>
<p>也可以这样使用</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;"># models/user_validator.rb</span><br />
<span style="color:#9966CC; font-weight:bold;">class</span> UserValidator <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::Validator</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> validate<span style="color:#006600; font-weight:bold;">&#40;</span>record<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; record.<span style="color:#9900CC;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:base</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;invalid name lenght&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> record.<span style="color:#9900CC;">name</span>.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">20</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#008000; font-style:italic;"># models/user.rb</span><br />
<span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> UserValidator<br />
&nbsp; validate_with MyValidator<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p><strong>2.attributes</strong><br />
平常我们给类对象定义属性的时候一般都用attr_accessor一类的方法,active_model提供了</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">define_attribute_methods一系列的方法<br />
<span style="color:#9966CC; font-weight:bold;">class</span> User<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::AttributeMethods</span><br />
&nbsp; attribute_method_affix &nbsp;<span style="color:#ff3333; font-weight:bold;">:prefix</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'prefix_'</span>, <span style="color:#ff3333; font-weight:bold;">:suffix</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'_suffix'</span><br />
<br />
&nbsp; define_attribute_methods <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
user = User.<span style="color:#9900CC;">new</span><br />
user.<span style="color:#9900CC;">methods</span>.<span style="color:#9900CC;">grep</span> <span style="color:#006600; font-weight:bold;">/</span>prefix_name<span style="color:#006600; font-weight:bold;">/</span> &nbsp;<br />
<span style="color:#008000; font-style:italic;"># =&gt; [&quot;prefix_name_suffix&quot;] 但是调用这个方法的时候会出错，期望beta过后能修正</span></div></div>
<p>3.callbacks<br />
callbacks很简单，与active_record类差不多,只是实现需要调用callbacks方法里面加上一个block</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> UserCallbacks <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">before_save</span><span style="color:#006600; font-weight:bold;">&#40;</span>obj<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#996600;">&quot;before_save call&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> User <br />
&nbsp; extend <span style="color:#6666ff; font-weight:bold;">ActiveModel::Callbacks</span><br />
&nbsp; <br />
&nbsp; define_model_callbacks <span style="color:#ff3333; font-weight:bold;">:save</span>,:only <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:before</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> save<br />
&nbsp; &nbsp; _run_save_callbacks <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#996600;">&quot;call save method&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># before_save UserCallbacks 这种方式也可以使用</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># 这个应该是datamapper里面的风格，active_record里没见过</span><br />
&nbsp; before_save <span style="color:#ff3333; font-weight:bold;">:save_callbacks</span><br />
<br />
&nbsp; protected<br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> save_callbacks<br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#996600;">&quot;save_callbacks call&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.neocanable.com/rails3-activemodel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rails关键字过滤</title>
		<link>http://www.neocanable.com/ruby-dfa-tree/</link>
		<comments>http://www.neocanable.com/ruby-dfa-tree/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 19:25:39 +0000</pubDate>
		<dc:creator>Neo</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://www.neocanable.com/?p=46</guid>
		<description><![CDATA[从前了解关键字过滤以为就是普通正则表达式的循环，原来关键词的过滤也是有算法的！！！ 下面是一个简单的实现的dfa词法树，写给一个论坛板块做关键词过滤的，随着关键词的递增，耗时与正则表达式比起来要节约很多 class WordReplacement &#60; ActiveRecord::Base &#160; def self.replacement_hash &#160; &#160; Hash&#91;*all.collect&#123;&#124;re&#124; &#91;re.regex_str,re.replacement&#93; &#125;.flatten&#93; &#160; end &#160; def self.filter_word_tree&#40;object = nil&#41; &#160; &#160; word_tree = Array.new&#40;256&#41; &#160; &#160; word_tree &#60;&#60; 0 &#160; &#160; object = replacement_hash if object.nil? &#160; &#160; object.each do &#124;word,replace&#124; &#160; &#160; &#160; temp &#160;= word_tree &#160; &#160; &#160; bytes = word.bytes.to_a [...]]]></description>
			<content:encoded><![CDATA[<p>从前了解关键字过滤以为就是普通正则表达式的循环，原来关键词的过滤也是有算法的！！！<br />
下面是一个简单的实现的dfa词法树，写给一个论坛板块做关键词过滤的，随着关键词的递增，耗时与正则表达式比起来要节约很多</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> WordReplacement <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">replacement_hash</span><br />
&nbsp; &nbsp; <span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">*</span>all.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>re<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span>re.<span style="color:#9900CC;">regex_str</span>,re.<span style="color:#9900CC;">replacement</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">flatten</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">filter_word_tree</span><span style="color:#006600; font-weight:bold;">&#40;</span>object = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; word_tree = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">256</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; word_tree <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006666;">0</span><br />
<br />
&nbsp; &nbsp; object = replacement_hash <span style="color:#9966CC; font-weight:bold;">if</span> object.<span style="color:#0000FF; font-weight:bold;">nil</span>?<br />
<br />
&nbsp; &nbsp; object.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>word,replace<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; temp &nbsp;= word_tree<br />
&nbsp; &nbsp; &nbsp; bytes = word.<span style="color:#9900CC;">bytes</span>.<span style="color:#9900CC;">to_a</span><br />
&nbsp; &nbsp; &nbsp; len &nbsp; = bytes.<span style="color:#9900CC;">size</span><br />
<br />
&nbsp; &nbsp; &nbsp; bytes.<span style="color:#9900CC;">each_with_index</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>asicc_code,arr_index<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> arr_index <span style="color:#006600; font-weight:bold;">&lt;</span> len <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> temp<span style="color:#006600; font-weight:bold;">&#91;</span>asicc_code<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; node = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">256</span><span style="color:#006600; font-weight:bold;">&#41;</span>,<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp<span style="color:#006600; font-weight:bold;">&#91;</span>asicc_code<span style="color:#006600; font-weight:bold;">&#93;</span> = node<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">elsif</span> temp<span style="color:#006600; font-weight:bold;">&#91;</span>asicc_code<span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#006666;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; node = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">256</span><span style="color:#006600; font-weight:bold;">&#41;</span>,<span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp<span style="color:#006600; font-weight:bold;">&#91;</span>asicc_code<span style="color:#006600; font-weight:bold;">&#93;</span> = node<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp = temp<span style="color:#006600; font-weight:bold;">&#91;</span>asicc_code<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp<span style="color:#006600; font-weight:bold;">&#91;</span>asicc_code<span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006666;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#008000; font-style:italic;"># end if</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#008000; font-style:italic;"># end bytes</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#008000; font-style:italic;"># end word</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>word_tree,<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">handle_word</span><span style="color:#006600; font-weight:bold;">&#40;</span>do_words,replace = <span style="color:#0000FF; font-weight:bold;">true</span>,word_tree = <span style="color:#0000FF; font-weight:bold;">nil</span>,word_hash = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; word_tree = filter_word_tree <span style="color:#9966CC; font-weight:bold;">if</span> word_tree.<span style="color:#0000FF; font-weight:bold;">nil</span>?<br />
&nbsp; &nbsp; word_hash = replacement_hash <span style="color:#9966CC; font-weight:bold;">if</span> word_hash.<span style="color:#0000FF; font-weight:bold;">nil</span>?<br />
&nbsp; &nbsp; temp &nbsp; &nbsp; &nbsp;= word_tree<br />
&nbsp; &nbsp; nodeTree &nbsp;= word_tree<br />
&nbsp; &nbsp; words &nbsp; &nbsp; = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; word &nbsp; &nbsp; &nbsp;= <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; to_replace= <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; a &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color:#006666;">0</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">while</span> a <span style="color:#006600; font-weight:bold;">&lt;</span> do_words.<span style="color:#9900CC;">size</span><br />
&nbsp; &nbsp; &nbsp; index = do_words<span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; temp = temp<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>index<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> temp.<span style="color:#0000FF; font-weight:bold;">nil</span>?<br />
&nbsp; &nbsp; &nbsp; &nbsp; temp = nodeTree<br />
&nbsp; &nbsp; &nbsp; &nbsp; a = a <span style="color:#006600; font-weight:bold;">-</span> word.<span style="color:#9900CC;">size</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; word = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; to_replace = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">elsif</span> temp == <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">or</span> temp<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#006666;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; word <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> index<br />
&nbsp; &nbsp; &nbsp; &nbsp; to_replace <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> a<br />
&nbsp; &nbsp; &nbsp; &nbsp; words <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> word<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> replace<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; replace_word = word_hash<span style="color:#006600; font-weight:bold;">&#91;</span>asicc_code_to_s<span style="color:#006600; font-weight:bold;">&#40;</span>word<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do_words<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">-</span>to_replace.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>,to_replace.<span style="color:#9900CC;">size</span><span style="color:#006600; font-weight:bold;">&#93;</span> = replace_word<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a = <span style="color:#006600; font-weight:bold;">&#40;</span>a <span style="color:#006600; font-weight:bold;">-</span> to_replace.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006600; font-weight:bold;">&#40;</span>replace_word.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a = a <span style="color:#006600; font-weight:bold;">-</span> word.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; word = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; to_replace = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; temp = nodeTree<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; word <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> index<br />
&nbsp; &nbsp; &nbsp; &nbsp; to_replace <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> a<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; a <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span> &nbsp; <br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> do_words <span style="color:#9966CC; font-weight:bold;">if</span> replace<br />
&nbsp; &nbsp; words.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> e.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>ch<span style="color:#006600; font-weight:bold;">|</span>ch.<span style="color:#9900CC;">chr</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; protected<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">asicc_code_to_s</span><span style="color:#006600; font-weight:bold;">&#40;</span>words<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; words.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> e.<span style="color:#9900CC;">chr</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.neocanable.com/ruby-dfa-tree/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>uninitialized constant MysqlCompat::MysqlRes</title>
		<link>http://www.neocanable.com/uninitialized-constant-mysqlcompat-mysqlres/</link>
		<comments>http://www.neocanable.com/uninitialized-constant-mysqlcompat-mysqlres/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 15:43:54 +0000</pubDate>
		<dc:creator>Neo</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[系统管理]]></category>

		<guid isPermaLink="false">http://www.neocanable.com/?p=193</guid>
		<description><![CDATA[export ARCHFLAGS=&#8221;-arch i386 -arch x86_64&#8243; ;sudo gem install &#8211;no-rdoc &#8211;no-ri -v=2.7 mysql &#8212; &#8211;with-mysql-dir=/usr/local/mysql &#8211;with-mysql-config=/usr/local/mysql/bin/mysql_config 64位的系统安装方法，装的时候其实主要找到mysql_config这个东西,我这里装的是2.7的gem]]></description>
			<content:encoded><![CDATA[<p>export ARCHFLAGS=&#8221;-arch i386 -arch x86_64&#8243; ;sudo gem install &#8211;no-rdoc &#8211;no-ri<br />
-v=2.7 mysql &#8212; &#8211;with-mysql-dir=/usr/local/mysql<br />
&#8211;with-mysql-config=/usr/local/mysql/bin/mysql_config</p>
<p>64位的系统安装方法，装的时候其实主要找到mysql_config这个东西,我这里装的是2.7的gem</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neocanable.com/uninitialized-constant-mysqlcompat-mysqlres/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rails sphinx全文检索</title>
		<link>http://www.neocanable.com/rails-sphinx/</link>
		<comments>http://www.neocanable.com/rails-sphinx/#comments</comments>
		<pubDate>Sun, 26 Sep 2010 15:40:12 +0000</pubDate>
		<dc:creator>Neo</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://www.neocanable.com/?p=187</guid>
		<description><![CDATA[1.安装mmseg这个ruby中文分词的扩展 wget http://www.coreseek.cn/uploads/csft/3.1/Source/mmseg-3.1.tar.gz &#160; &#160; tar xzvf mmseg-3.1.tar.gz &#160; &#160; cd mmseg-3.1 &#160; &#160; chmod a+x configure &#160; &#160; ./configure &#38;&#38; make &#38;&#38; make install 安装ruby扩展 cd ruby &#160; &#160; cp /usr/local/include/mmseg/*.h . &#160; &#160; cp ../src/*.h . &#160; &#160; cp ../src/css/*.h . &#160; &#160; ruby extconf.lin.rb &#160; &#160; make &#38;&#38; make install cd ../data [...]]]></description>
			<content:encoded><![CDATA[<p>1.安装mmseg这个ruby中文分词的扩展</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">wget http:<span style="color:#006600; font-weight:bold;">//</span>www.<span style="color:#9900CC;">coreseek</span>.<span style="color:#9900CC;">cn</span><span style="color:#006600; font-weight:bold;">/</span>uploads<span style="color:#006600; font-weight:bold;">/</span>csft<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">3.1</span><span style="color:#006600; font-weight:bold;">/</span>Source<span style="color:#006600; font-weight:bold;">/</span>mmseg<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">3.1</span>.<span style="color:#9900CC;">tar</span>.<span style="color:#9900CC;">gz</span><br />
&nbsp; &nbsp; tar xzvf mmseg<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">3.1</span>.<span style="color:#9900CC;">tar</span>.<span style="color:#9900CC;">gz</span><br />
&nbsp; &nbsp; cd mmseg<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">3.1</span><br />
&nbsp; &nbsp; chmod a<span style="color:#006600; font-weight:bold;">+</span>x configure<br />
&nbsp; &nbsp; .<span style="color:#006600; font-weight:bold;">/</span>configure <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> make <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> make install</div></div>
<p>安装ruby扩展</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cd ruby<br />
&nbsp; &nbsp; cp <span style="color:#006600; font-weight:bold;">/</span>usr<span style="color:#006600; font-weight:bold;">/</span>local<span style="color:#006600; font-weight:bold;">/</span><span style="color:#9966CC; font-weight:bold;">include</span><span style="color:#006600; font-weight:bold;">/</span>mmseg<span style="color:#006600; font-weight:bold;">/*</span>.<span style="color:#9900CC;">h</span> .<br />
&nbsp; &nbsp; <span style="color:#9900CC;">cp</span> ..<span style="color:#006600; font-weight:bold;">/</span>src<span style="color:#006600; font-weight:bold;">/*</span>.<span style="color:#9900CC;">h</span> .<br />
&nbsp; &nbsp; <span style="color:#9900CC;">cp</span> ..<span style="color:#006600; font-weight:bold;">/</span>src<span style="color:#006600; font-weight:bold;">/</span>css<span style="color:#006600; font-weight:bold;">/*</span>.<span style="color:#9900CC;">h</span> .<br />
&nbsp; &nbsp; <span style="color:#9900CC;">ruby</span> extconf.<span style="color:#9900CC;">lin</span>.<span style="color:#9900CC;">rb</span><br />
&nbsp; &nbsp; make <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> make install</div></div>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cd ..<span style="color:#006600; font-weight:bold;">/</span>data<br />
&nbsp; &nbsp; mmseg <span style="color:#006600; font-weight:bold;">-</span>u unigram.<span style="color:#9900CC;">txt</span><br />
&nbsp; &nbsp; 将生成的词库重命名为uni.<span style="color:#9900CC;">lib</span><br />
&nbsp; &nbsp; cp uni.<span style="color:#9900CC;">lib</span> ..<span style="color:#006600; font-weight:bold;">/</span>ruby<br />
&nbsp; &nbsp; cd ..<span style="color:#006600; font-weight:bold;">/</span>ruby<br />
&nbsp; &nbsp; ruby test.<span style="color:#9900CC;">rb</span></div></div>
<p>如果运行成功的话，安装完毕了</p>
<p>2.安装 csft3.2</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;wget http:<span style="color:#006600; font-weight:bold;">//</span>www.<span style="color:#9900CC;">coreseek</span>.<span style="color:#9900CC;">cn</span><span style="color:#006600; font-weight:bold;">/</span>uploads<span style="color:#006600; font-weight:bold;">/</span>csft<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">3.2</span><span style="color:#006600; font-weight:bold;">/</span>csft<span style="color:#006600; font-weight:bold;">-</span>3.2.12.<span style="color:#9900CC;">tar</span>.<span style="color:#9900CC;">gz</span><br />
&nbsp; &nbsp; tar xzvf csft<span style="color:#006600; font-weight:bold;">-</span>3.2.12.<span style="color:#9900CC;">tar</span>.<span style="color:#9900CC;">gz</span><br />
&nbsp; &nbsp; cd csft<span style="color:#006600; font-weight:bold;">-</span>3.2.12<br />
&nbsp; &nbsp; .<span style="color:#006600; font-weight:bold;">/</span>configure <span style="color:#006600; font-weight:bold;">--</span>with<span style="color:#006600; font-weight:bold;">-</span>mysql=<span style="color:#006600; font-weight:bold;">/</span>usr<span style="color:#006600; font-weight:bold;">/</span>local<span style="color:#006600; font-weight:bold;">/</span>mysql<br />
&nbsp; &nbsp; make <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> make install</div></div>
<p>3.安装sphinx插件<br />
    ruby script\plugin install git://github.com/freelancing-god/thinking-sphinx.git<br />
    注释掉： Rails.configuration.cache_classes = false,这个在我这里是第行</p>
<p>    rake ts:config<br />
    vi config/development.sphinx.conf<br />
    将 charset_type = utf-8 改为 charset_type = zh_cn.utf-8<br />
    并且在下面添加：charset_dictpath = /usr/local/csft/var/data    # 这里的意思是存放词库的地址,也就是刚刚使用mmseg -u生成的那个文件</p>
<p>4.测试</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neocanable.com/rails-sphinx/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>rails连接sqlserver2000,2005,2008</title>
		<link>http://www.neocanable.com/rails%e8%bf%9e%e6%8e%a5sqlserver200020052008/</link>
		<comments>http://www.neocanable.com/rails%e8%bf%9e%e6%8e%a5sqlserver200020052008/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 17:33:25 +0000</pubDate>
		<dc:creator>Neo</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://www.neocanable.com/?p=179</guid>
		<description><![CDATA[download unixODBC-2.3.0.tar.gz tar xzvf unixODBC-2.3.0.tar.gz cd unixODBC-2.3.0 ./configure --enable-drivers &#160; &#160;--enable-driver-conf &#160; &#160;--enable-dependency-tracking &#160; &#160;--prefix=/usr/local/unixODBC &#160; &#160;--sysconfdir=/etc --enable-gui=no make &#38;&#38; make install download freetds-0.82.tar.gz tar xzvf freetds-0.82.tar.gz cd freetds-0.82 ./configure --enable-msdblib &#160; &#160; &#160; &#160;--sysconfdir=/etc/ &#160; &#160; &#160; &#160;--with-unixodbc=/usr/local/unixODBC/ &#160; &#160; &#160; &#160;--with-tdsver=8.0 &#160; &#160; &#160; &#160;--prefix=/usr/local/freetds-with-unixodbc/ make &#38;&#38; make install download http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9999.tar.gz 安装ruby的odbc扩展,千万不要下载0.9997 tar [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">download unixODBC-2.3.0.tar.gz<br />
tar xzvf unixODBC-2.3.0.tar.gz<br />
cd unixODBC-2.3.0<br />
./configure --enable-drivers<br />
&nbsp; &nbsp;--enable-driver-conf<br />
&nbsp; &nbsp;--enable-dependency-tracking<br />
&nbsp; &nbsp;--prefix=/usr/local/unixODBC<br />
&nbsp; &nbsp;--sysconfdir=/etc --enable-gui=no<br />
make &amp;&amp; make install</div></div>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">download freetds-0.82.tar.gz<br />
tar xzvf freetds-0.82.tar.gz<br />
cd freetds-0.82<br />
./configure --enable-msdblib<br />
&nbsp; &nbsp; &nbsp; &nbsp;--sysconfdir=/etc/<br />
&nbsp; &nbsp; &nbsp; &nbsp;--with-unixodbc=/usr/local/unixODBC/<br />
&nbsp; &nbsp; &nbsp; &nbsp;--with-tdsver=8.0<br />
&nbsp; &nbsp; &nbsp; &nbsp;--prefix=/usr/local/freetds-with-unixodbc/<br />
make &amp;&amp; make install</div></div>
<p>download http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9999.tar.gz<br />
安装ruby的odbc扩展,千万不要下载0.9997</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">tar xzvf ruby-odbc-0.9999.tar.gz<br />
cd ruby-odbc-0.9999<br />
ruby extconf.rb --with-odbc-dir=/usr/local/unixODBC<br />
&nbsp; --ruby=/usr/local/bin/ruby<br />
&nbsp; --diable-dlopen<br />
make &amp;&amp; make install</div></div>
<p>/etc/odbc.ini</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[HXDB]<br />
Driver= FreeTDS<br />
Description=ODBC connection via FreeTDS<br />
Trace=yes<br />
TraceFile=/tmp/odbc_tr<br />
Servername=hxdb<br />
Database=MR2000DB</div></div>
<p>/etc/odbcinst.ini</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[FreeTDS]<br />
Description=TDS driver (Sybase/MS SQL)<br />
Driver=/usr/local/freetds-with-unixodbc/lib/libtdsodbc.so<br />
FileUsage=1</div></div>
<p>odbc.ini和odbcinst.ini这两个文件每行都不要留空格或者制表格，不然的话会出错</p>
<p>/etc/freetds.conf(这里192.168.1.16是sqlserver的地址)</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[hxdb]<br />
&nbsp; &nbsp; host = 192.168.1.16<br />
&nbsp; &nbsp; port = 1433<br />
&nbsp; client charset = UTF-8</div></div>
<p>安装rails连接mssql所需要的gem</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gem install dbd-odbc<br />
gem install dbi<br />
gem install activerecord-sqlserver-adapter -v=2.3.8</div></div>
<p><strong>我在公司最后一次写这样的安装文档&#8230;&#8230;&#8230;</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.neocanable.com/rails%e8%bf%9e%e6%8e%a5sqlserver200020052008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

