﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-子在川上曰</title><link>http://www.blogjava.net/chengang/</link><description>　　逝者如斯夫不舍昼夜</description><language>zh-cn</language><lastBuildDate>Fri, 24 Apr 2026 05:38:38 GMT</lastBuildDate><pubDate>Fri, 24 Apr 2026 05:38:38 GMT</pubDate><ttl>60</ttl><item><title>《Eclipse从入门到精通》随书光盘地址</title><link>http://www.blogjava.net/chengang/archive/2017/12/29/432993.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Fri, 29 Dec 2017 07:37:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2017/12/29/432993.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/432993.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2017/12/29/432993.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/432993.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/432993.html</trackback:ping><description><![CDATA[<div>我的新博客地址：&nbsp;<a href="http://www.yowob.cn">yowob.cn</a></div>
<div><br />
<div><span style="font-family: arial;">书的软件和代码放在百度网盘：</span><a href="https://pan.baidu.com/s/1kVb31aR" _src="https://pan.baidu.com/s/1kVb31aR" target="_blank" style="word-break: break-word; font-family: arial;">https://pan.baidu.com/s/1kVb31aR</a></div>
<div><br />
</div>
<div><br />
</div>
</div><img src ="http://www.blogjava.net/chengang/aggbug/432993.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2017-12-29 15:37 <a href="http://www.blogjava.net/chengang/archive/2017/12/29/432993.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>二级域名的java实现</title><link>http://www.blogjava.net/chengang/archive/2010/12/29/341939.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Wed, 29 Dec 2010 15:19:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2010/12/29/341939.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/341939.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2010/12/29/341939.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/341939.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/341939.html</trackback:ping><description><![CDATA[最近在做一个自建网站平台(<a href="http://www.yowob.com">http://www.yowob.com</a>&nbsp;)，其他涉及到为用户提供一个二级域名功能，实现方法如下：<br />
<br />
(1)首先要在域名服务商端做一个泛域名解析. 我用的是godaddy.com,就新建一个A记录(host=*,point to指向我的服务器的ip),这样所有二级域名都会转到我的服务器来了<br />
<br />
(2)接着在web.xml配一个自已写的域名过滤器,<br />
<br />
<div style="padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; border-left-color: #cccccc; word-break: break-all; padding-top: 4px"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;URLFilter&lt;/filter-name&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-class&gt;com.yowob.commons.URLFilter&lt;/filter-class&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-mapping&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;URLFilter&lt;/filter-name&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter-mapping&gt;</span></div>
<br />
过滤器的代码如下。这里先将二级域名和全球域名和用户ID的映射,保存在一个数据表里, 然后访问进来时对地址做一个判断, 再取出对应的用户ID. 再转一下就行了. 我的静态文件都在static目录，所以还加了一个static的判断。<br />
比如: <a href="http://time.you.com/board/21">http://time.you.com/board/21</a> 用time对应用户ID为6,则访问效果有&nbsp;<a href="http://time.you.com/board/21">http://www.you.com/6/board/21</a>相同, 不过地址栏还是显示<a href="http://time.you.com/board/21">http://time.you.com/board/21</a>。<br />
再比如：htttp://www.userdomain.com/board/21，这个是用户ID为6的全球域名，访问效果也和上面一样。<br />
<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><span style="color: #0000ff">package</span><span style="color: #000000">&nbsp;com.yowob.commons;<br />
<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.io.IOException;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.HashMap;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.List;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.Map;<br />
<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;javax.servlet.Filter;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;javax.servlet.FilterChain;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;javax.servlet.FilterConfig;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;javax.servlet.ServletException;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;javax.servlet.ServletRequest;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;javax.servlet.ServletResponse;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;javax.servlet.http.HttpServletRequest;<br />
<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;org.apache.commons.lang.StringUtils;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;org.apache.commons.lang.math.NumberUtils;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;org.apache.commons.logging.Log;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;org.apache.commons.logging.LogFactory;<br />
<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;com.yowob.Constants;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;com.yowob.dao.SiteDAO;<br />
</span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;com.yowob.dto.SiteDTO;<br />
<br />
</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;URLFilter&nbsp;</span><span style="color: #0000ff">implements</span><span style="color: #000000">&nbsp;Filter&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">final</span><span style="color: #000000">&nbsp;Log&nbsp;log&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;LogFactory.getLog(URLFilter.</span><span style="color: #0000ff">class</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">final</span><span style="color: #000000">&nbsp;String&nbsp;DOMAIN_END&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">.</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;Constants.DOMAIN;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">.you.com</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">final</span><span style="color: #000000">&nbsp;Map</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Long</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;NAME_MAP&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;HashMap</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Long</span><span style="color: #000000">&gt;</span><span style="color: #000000">();<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">final</span><span style="color: #000000">&nbsp;Map</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Long</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;DOMAIN_MAP&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;HashMap</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Long</span><span style="color: #000000">&gt;</span><span style="color: #000000">();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;init(FilterConfig&nbsp;filterConfig)&nbsp;</span><span style="color: #0000ff">throws</span><span style="color: #000000">&nbsp;ServletException&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(</span><span style="color: #000000">"</span><span style="color: #000000">------------------------------init</span><span style="color: #000000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SiteDAO&nbsp;siteDAO&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;SiteDAO();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List</span><span style="color: #000000">&lt;</span><span style="color: #000000">SiteDTO</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;list&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;siteDAO.getAll();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(SiteDTO&nbsp;siteDTO&nbsp;:&nbsp;list)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;name&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;siteDTO.getName();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(StringUtils.isNotEmpty(name))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NAME_MAP.put(name,&nbsp;siteDTO.getId());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;domain&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;siteDTO.getDomain();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(StringUtils.isNotEmpty(domain))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DOMAIN_MAP.put(domain,&nbsp;siteDTO.getId());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;updateName(String&nbsp;oldValue,&nbsp;String&nbsp;newValue,&nbsp;Long&nbsp;siteId)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(StringUtils.equals(oldValue,&nbsp;newValue))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(StringUtils.isNotEmpty(oldValue))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NAME_MAP.remove(oldValue);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(StringUtils.isNotEmpty(newValue))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NAME_MAP.put(newValue,&nbsp;siteId);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;updateDomain(String&nbsp;oldValue,&nbsp;String&nbsp;newValue,&nbsp;Long&nbsp;siteId)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(StringUtils.equals(oldValue,&nbsp;newValue))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(StringUtils.isNotEmpty(oldValue))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DOMAIN_MAP.remove(oldValue);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(StringUtils.isNotEmpty(newValue))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DOMAIN_MAP.put(newValue,&nbsp;siteId);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;destroy()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(</span><span style="color: #000000">"</span><span style="color: #000000">------------------------------destroy</span><span style="color: #000000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;doFilter(ServletRequest&nbsp;servletRequest,&nbsp;ServletResponse&nbsp;response,&nbsp;FilterChain&nbsp;filterChain)&nbsp;</span><span style="color: #0000ff">throws</span><span style="color: #000000">&nbsp;IOException,&nbsp;ServletException&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpServletRequest&nbsp;request&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(HttpServletRequest)&nbsp;servletRequest;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;requestURI&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;request.getRequestURI();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;serverName&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;request.getServerName().toLowerCase();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;realURI&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;getRealRequestURI(serverName,&nbsp;requestURI);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.getRequestDispatcher(realURI).forward(request,&nbsp;response);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;String&nbsp;getRealRequestURI(String&nbsp;serverName,&nbsp;String&nbsp;requestURI)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(Constants.WWW_DOMAIN.equals(serverName)&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;requestURI.startsWith(</span><span style="color: #000000">"</span><span style="color: #000000">/static/</span><span style="color: #000000">"</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;Constants.DOMAIN.equals(serverName))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;requestURI;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(serverName.endsWith(DOMAIN_END))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;secondDomain&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;serverName.substring(</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;serverName.indexOf(</span><span style="color: #000000">"</span><span style="color: #000000">.</span><span style="color: #000000">"</span><span style="color: #000000">));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">网站id</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(NumberUtils.isNumber(secondDomain))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;getURI(secondDomain,&nbsp;requestURI);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">网站英文名</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Long&nbsp;siteId&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;NAME_MAP.get(secondDomain);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(siteId&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">保留的二级域名</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(Constants.isPrivateSecondDomain(secondDomain))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;requestURI;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">/message?msg=不存在二级域名</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;secondDomain;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException("do&nbsp;not&nbsp;exist&nbsp;second&nbsp;domain:&nbsp;"&nbsp;+&nbsp;secondDomain);</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;getURI(siteId&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">""</span><span style="color: #000000">,&nbsp;requestURI);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">域名</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Long&nbsp;siteId&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;DOMAIN_MAP.get(serverName);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(siteId&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;requestURI;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;getURI(siteId&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">""</span><span style="color: #000000">,&nbsp;requestURI);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;String&nbsp;getURI(String&nbsp;siteId,&nbsp;String&nbsp;requestURI)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(requestURI.equals(</span><span style="color: #000000">"</span><span style="color: #000000">/</span><span style="color: #000000">"</span><span style="color: #000000">))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">/</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;siteId;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">/</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;siteId&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;requestURI;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
}</span></div>
<br />
<br />
其他一些小技巧：<br />
（１）为了便于本机测试，可以修改windows 的hosts文件。我的如下：<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><span style="color: #000000">127.0</span><span style="color: #000000">.</span><span style="color: #000000">0.1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;localhost<br />
</span><span style="color: #000000">127.0</span><span style="color: #000000">.</span><span style="color: #000000">0.1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;you.com<br />
</span><span style="color: #000000">127.0</span><span style="color: #000000">.</span><span style="color: #000000">0.1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;www.you.com<br />
</span><span style="color: #000000">127.0</span><span style="color: #000000">.</span><span style="color: #000000">0.1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time1.you.com<br />
</span><span style="color: #000000">127.0</span><span style="color: #000000">.</span><span style="color: #000000">0.1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time2.you.com<br />
</span><span style="color: #000000">127.0</span><span style="color: #000000">.</span><span style="color: #000000">0.1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">6</span><span style="color: #000000">.you.com<br />
</span><span style="color: #000000">127.0</span><span style="color: #000000">.</span><span style="color: #000000">0.1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;www.bobo.com</span></div>
<br />
（２）web页的各种地址则要注意相对路径的问题。主要考虑<br />
首先设置&lt;base href="http://www.yowob.com/" /&gt;，或&lt;base href="http://www.yowob.com/6/" /&gt;其中地址最后要加一个/<br />
然后页面中其他地址前面不加/，就是相对地址（以地址栏为基础）。加上/，则是绝对地址。<br />
<img src ="http://www.blogjava.net/chengang/aggbug/341939.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2010-12-29 23:19 <a href="http://www.blogjava.net/chengang/archive/2010/12/29/341939.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VIM的常用插件+配置文件+资料</title><link>http://www.blogjava.net/chengang/archive/2007/10/18/153970.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Thu, 18 Oct 2007 10:15:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2007/10/18/153970.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/153970.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2007/10/18/153970.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/153970.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/153970.html</trackback:ping><description><![CDATA[用VIM来开发rails也挺不错的，自完代码完成，代码颜色等功能都有。也算netbean、eclipse之外的轻量级选择吧。<br />
我把VIM的常用插件，自己用的配置文件，收罗的一些资料一并打包了，省得初用VIM的人找来找去浪费时间。<br /><br /><a title="http://www.blogjava.net/Files/chengang/myvim.zip" href="/Files/chengang/myvim.zip">http://www.blogjava.net/Files/chengang/myvim.zip</a><br /><br /><br /><br />在ubuntu7.10中的gvim出现乱码，这时需要在主目录下的“.vimrc”文件中加上定义字体的一句。我用的是“微软雅黑”字体所以此句为：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">set guifont</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">YaHei\ Consolas\ Hybrid\ </span><span style="color: rgb(0, 0, 0);">10</span></div>注意：字体名中有空格的，用斜杠分开，而且斜杠后面一定要有一个空格。10是字体大小，前面有一个空格。<br /><img src ="http://www.blogjava.net/chengang/aggbug/153970.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2007-10-18 18:15 <a href="http://www.blogjava.net/chengang/archive/2007/10/18/153970.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>个性化页面布局的设计思考与Rails初步实现</title><link>http://www.blogjava.net/chengang/archive/2007/10/11/151900.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Wed, 10 Oct 2007 16:00:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2007/10/11/151900.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/151900.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2007/10/11/151900.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/151900.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/151900.html</trackback:ping><description><![CDATA[象博客，以及google的iGoogle，都可以个性化页面布局---对页面模块增删改，以及调整位置。这种效果是如何实现的呢？在我的项目中也面临到
这个需求。我最初的解决方法是创建几个典型的rhtml布局组合。但这远远不够，而且不灵活，在形式上也不统一。于是我再次修改了设计，之后似乎可以基本
解决这个问题了。希望感兴趣的朋友一起来讨论。<br /><br />
这个设计其实很简单，就是“引擎+配置“--主体页面只定义一个rthml，可以把它看做页面引擎，然后用一个配置文件指定了页面所应具有的模块和数据。
页面模块就象一个个装有数据的盒子，通过“页面引擎 +
配置文件”把这些盒子组合起来，象搭积木一样。页面引擎是各用户共用的，配置文件是各用户独有的，这样一装配起来，就形成了用户的个性化页面。<br /><br />
剩下的重点就是怎么定义配置文件。首先是要划清配置文件的责任界线----它只负责定义盒子里的数据，还有盒子的嵌套关系，而大小和位置等布局方面则全部交给CSS去负责。<br /><br />
上面是初步想法，下面看看具体实现，代码仅供参考<br /><br />
以下是某个用户的配置文件（我没用XML，而是用YAML）。board_1是指ID=1这个栏目所用的配置定义。topContent是一个<div>&lt;div&gt;的id值，我把每个栏目的页面分成<span>topContent顶、sideContent边（左或右由CSS决定）、</span><span>primaryContent
主要、bottomContent底。topic是指添加一个模块（盒子），显示一个主题内容。和topic类似是还有显示图像的image、显示主题列
表的topics、显示分类列表的categories等等等等。它们各有不同的属性值，比如topic模块，它需要定指它的主题id，以及它所用的
view(topics/_show_hot.rhtml  or  topics/_show.rhtml等等)。<br /><br />（虽然这个配置文件抽象得还不够，但这样子已经可以解决我的需要了，那</span><span></span><span>就</span><span>暂时</span><span>这样先了。）<br /><br /></span>template.yml<br /><div class="dp-highlighter"><div class="bar"> </div><ol start="1" class="dp-j"><li class="alt"><span><span>board_2:  </span></span></li><li class=""><span>  </span></li><li class="alt"><span>board_1:  </span></li><li class=""><span>- topContent:  </span></li><li class="alt"><span>  - topic:  </span></li><li class=""><span>      topic_id: <span class="number">7</span><span>  </span></span></li><li class="alt"><span>      view: topics/show_hot  </span></li><li class=""><span>- sideContent:  </span></li><li class="alt"><span>  - image:  </span></li><li class=""><span>      url: /images/news.jpg  </span></li><li class="alt"><span>  - categories:  </span></li><li class=""><span>      board: <span class="number">5</span><span>  </span></span></li><li class="alt"><span>      view: tree  </span></li><li class=""><span>  - topics:  </span></li><li class="alt"><span>      board: <span class="number">5</span><span>  </span></span></li><li class=""><span>      per_page: <span class="number">4</span><span>  </span></span></li><li class="alt"><span>      view: index_simple  </span></li><li class=""><span>  - topics:  </span></li><li class="alt"><span>      board: <span class="number">6</span><span>  </span></span></li><li class=""><span>- primaryContent:  </span></li><li class="alt"><span>  - topics:  </span></li><li class=""><span>      board: <span class="number">4</span><span>  </span></span></li><li class="alt"><span>      view: index  </span></li><li class=""><span>  - topic:  </span></li><li class="alt"><span>      topic_id: <span class="number">7</span><span>  </span></span></li><li class=""><span>      view: util/box  </span></li><li class="alt"><span>  </span></li><li class=""><span>board_3:  </span></li></ol></div><br />
然后在controller里把配置文件读入，再转化成模型类。我把各个界面模块看做一个个盒子Box<br />
这是它的顶级Box<br /><div class="code_title">ruby 代码</div><div class="dp-highlighter"><div class="bar"> </div><ol start="1" class="dp-rb"><li class="alt"><span><span class="keyword">class</span><span> Box  </span></span></li><li class=""><span>  attr_accessor <span class="symbol">:html_id</span><span>, </span><span class="symbol">:view</span><span>, </span><span class="symbol">:boxes</span><span>  </span></span></li><li class="alt"><span>  <span class="keyword">def</span><span> initialize</span><span><br /></span></span></li><li class=""><span>    <span class="variable">@boxes</span><span>=[]  </span></span></li><li class="alt"><span>  <span class="keyword">end</span><span>  </span></span></li><li class=""><span><span class="keyword">end</span><span>  </span></span></li></ol></div><br />
这是topic模块的<br /><div class="code_title">ruby 代码</div><div class="dp-highlighter"><div class="bar"> </div><ol start="1" class="dp-rb"><li class="alt"><span><span class="keyword">class</span><span> TopicBox &lt; Box  </span></span></li><li class=""><span>  attr_accessor <span class="symbol">:topic_id</span><span>  </span></span></li><li class="alt"><span><span class="keyword">end</span><span>  </span></span></li></ol></div><br />
这是Image模块的<br /><div class="code_title">ruby 代码</div><div class="dp-highlighter"><div class="bar"> </div><ol start="1" class="dp-rb"><li class="alt"><span><span class="keyword">class</span><span> ImageBox &lt; Box  </span></span></li><li class=""><span>  attr_accessor <span class="symbol">:url</span><span>  </span></span></li><li class=""><span><span class="keyword">end</span><span>  </span>   <br /></span></li></ol></div><br />
.....等 等， 其他的Box子类大同小异<br /><br />
然后在一个controller里把这些配置信息转成Box模型类<br /><div class="code_title">ruby 代码</div><div class="dp-highlighter"><div class="bar"> </div><ol start="1" class="dp-rb"><li class="alt"><span><span>templates =  YAML::load(File.read("public/uploads/#{user_id}/config/template.yml"))</span><span><br /></span></span></li><li class=""><span>template = templates.find{<span class="variable">|o</span><span>| o[0]==</span><span class="string">"board_#{@board.id}"</span><span> }  </span></span></li><li class="alt"><span>args = template[1]  </span></li><li class=""><span>  </span></li><li class="alt"><span><span class="variable">@boxes</span><span> = []  </span></span></li><li class=""><span>args.<span class="keyword">each</span><span> </span><span class="keyword">do</span><span> </span><span class="variable">|arg1_hash</span><span>|  </span></span></li><li class="alt"><span>  arg1_hash.<span class="keyword">each</span><span> </span><span class="keyword">do</span><span> </span><span class="variable">|key1</span><span>, value1|  </span></span></li><li class=""><span>    board_box = BoardBox.<span class="keyword">new</span><span>  </span></span></li><li class="alt"><span>    board_box.html_id = key1  </span></li><li class=""><span>    <span class="variable">@boxes</span><span> &lt;&lt; board_box  </span></span></li><li class="alt"><span>    value1.<span class="keyword">each</span><span> </span><span class="keyword">do</span><span> </span><span class="variable">|arg2_hash</span><span>|  </span></span></li><li class=""><span>      arg2_hash.<span class="keyword">each</span><span> </span><span class="keyword">do</span><span> </span><span class="variable">|key2</span><span>, value2|  </span></span></li><li class="alt"><span>        <span class="keyword">case</span><span> key2  </span></span></li><li class=""><span>        <span class="keyword">when</span><span> 'topics'  </span></span></li><li class="alt"><span>          box = TopicsBox.<span class="keyword">new</span><span>  </span></span></li><li class=""><span>          box.board_id = value2['board']  </span></li><li class="alt"><span>          box.per_page = value2['per_page']|<span class="variable">|2</span><span>  </span></span></li><li class=""><span>          box.view = value2['view']||'index_simple'  </span></li><li class="alt"><span>          board_box.boxes &lt;&lt; box   </span></li><li class=""><span>        <span class="keyword">when</span><span> 'categories'  </span></span></li><li class="alt"><span>          box = CategoriesBox.<span class="keyword">new</span><span>  </span></span></li><li class=""><span>          box.board_id = value2['board']  </span></li><li class="alt"><span>          box.view = value2['view']||'list'  </span></li><li class=""><span>          board_box.boxes &lt;&lt; box   </span></li><li class="alt"><span>        <span class="keyword">when</span><span> 'image'  </span></span></li><li class=""><span>          box = ImageBox.<span class="keyword">new</span><span>  </span></span></li><li class="alt"><span>          box.url = value2['url']  </span></li><li class=""><span>          board_box.boxes &lt;&lt; box   </span></li><li class="alt"><span>        <span class="keyword">when</span><span> 'topic'  </span></span></li><li class=""><span>          box = TopicBox.<span class="keyword">new</span><span>  </span></span></li><li class="alt"><span>          box.topic_id = value2['topic_id']  </span></li><li class=""><span>          box.view = value2['view']||'util/box'  </span></li><li class="alt"><span>          board_box.boxes &lt;&lt; box   </span></li><li class=""><span>        <span class="keyword">end</span><span>  </span></span></li><li class="alt"><span>      <span class="keyword">end</span><span>  </span></span></li><li class=""><span>    <span class="keyword">end</span><span>  </span></span></li><li class="alt"><span>  <span class="keyword">end</span><span>  </span></span></li><li class="alt"><span><span class="keyword">end</span><span>  </span><br /></span></li></ol></div><br />
最后是它页面引擎（逻辑代码和页面代码混在一起，比较丑陋）
<div class="code_title">ruby 代码</div><div class="dp-highlighter"><div class="bar"> </div><ol start="1" class="dp-rb"><li class="alt"><span><span>&lt;% </span><span class="variable">@boxes</span><span>.</span><span class="keyword">each</span><span> </span><span class="keyword">do</span><span> </span><span class="variable">|box1</span><span>| %&gt;  </span></span></li><li class=""><span><div id><span class="string">"&lt;%=box1.html_id%&gt;"</span><span>&gt;  </span></div id>/span&gt;</span></li><li class="alt"><span>  &lt;% box1.boxes.<span class="keyword">each</span><span> </span><span class="keyword">do</span><span> </span><span class="variable">|box2</span><span>|  </span></span></li><li class=""><span>       p1 box2.<span class="keyword">class</span><span>.to_s  </span></span></li><li class="alt"><span>  </span></li><li class=""><span>      <span class="keyword">case</span><span> box2.</span><span class="keyword">class</span><span>.to_s  </span></span></li><li class="alt"><span>      <span class="keyword">when</span><span> 'TopicsBox'  </span></span></li><li class=""><span>        board_id = box2.board_id  </span></li><li class="alt"><span>        <span class="keyword">if</span><span> board_id  </span></span></li><li class=""><span>          board = Board.find(board_id)  </span></li><li class="alt"><span>          topics = Topic.by_board_id(board_id, <span class="symbol">:per_page</span><span> =&gt; box2.per_page)   </span></span></li><li class=""><span>          %&gt;  </span></li><li class="alt"><span>          &lt;%= render(<span class="symbol">:partial</span><span> =&gt; </span><span class="string">"topics/#{box2.view}"</span><span>, </span><span class="symbol">:locals</span><span> =&gt; {</span><span class="symbol">:title</span><span> =&gt;board.title, </span><span class="symbol">:topics</span><span> =&gt; topics })%&gt;  </span></span></li><li class=""><span>        &lt;%<span class="keyword">end</span><span>  </span></span></li><li class="alt"><span>      <span class="keyword">when</span><span> 'CategoriesBox'  </span></span></li><li class=""><span>        board_id = box2.board_id  </span></li><li class="alt"><span>        <span class="keyword">if</span><span> board_id  </span></span></li><li class=""><span>          board = Board.find(board_id)  </span></li><li class="alt"><span>          categories = board.categories  </span></li><li class=""><span>          %&gt;  </span></li><li class="alt"><span>          &lt;%= render <span class="symbol">:partial</span><span> =&gt; </span><span class="string">"categories/#{box2.view}"</span><span>, </span><span class="symbol">:locals</span><span> =&gt; {</span><span class="symbol">:board</span><span> =&gt;board, </span><span class="symbol">:categories</span><span> =&gt; categories } %&gt;  </span></span></li><li class=""><span>        &lt;%<span class="keyword">end</span><span>%&gt;  </span></span></li><li class="alt"><span>      &lt;%<span class="keyword">when</span><span> 'ImageBox'%&gt;  </span></span></li><li class=""><span>        &lt;%= box_tag <span class="symbol">:header</span><span>=&gt;</span><span class="keyword">false</span><span>%&gt;  </span></span></li><li class="alt"><span>          &lt;%=image_tag(box2.url, <span class="symbol">:border</span><span> =&gt; 0) %&gt;  </span></span></li><li class=""><span>        &lt;%= end_box_tag %&gt;  </span></li><li class="alt"><span>      &lt;%<span class="keyword">when</span><span> 'TopicBox'  </span></span></li><li class=""><span>        topic = Topic.find(box2.topic_id) %&gt;  </span></li><li class="alt"><span>        &lt;%=render(<span class="symbol">:partial</span><span> =&gt; </span><span class="string">"#{box2.view}"</span><span>, </span><span class="symbol">:locals</span><span> =&gt; {</span><span class="symbol">:title</span><span> =&gt;topic.title, </span><span class="symbol">:content</span><span> =&gt; topic.content, </span><span class="symbol">:topic</span><span> =&gt; topic })%&gt;  </span></span></li><li class=""><span>      &lt;%<span class="keyword">end</span><span>  </span></span></li><li class=""><span>  <span class="keyword">end</span><span>%&gt;  </span></span></li></ol></div>  <br /></div><br />
这样，以后想在页面上增加删除什么模块，修改配置文件就行了。当然给用户用，还必须得用AJAX来写个GUI界面，总不能让用户手工去改配置文件吧。<br /><img src ="http://www.blogjava.net/chengang/aggbug/151900.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2007-10-11 00:00 <a href="http://www.blogjava.net/chengang/archive/2007/10/11/151900.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>抽取FCKEditor的浏览图片功能</title><link>http://www.blogjava.net/chengang/archive/2007/09/26/148412.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Wed, 26 Sep 2007 10:49:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2007/09/26/148412.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/148412.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2007/09/26/148412.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/148412.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/148412.html</trackback:ping><description><![CDATA[过去，我们上传图片，一般都是一个文本框加一个“浏览”按钮，通过浏览按钮选取本地的图片，然后在提交表单后的逻辑中将图片上传至服务器。现在，我们已经把FCKEditor应用在了我们的系统里，而FCKEditor中带了有了图片上传和浏览功能。所以我就想让这个“浏览”按钮不是从本地选取图片，而是从FCKEditor传到服务器上的图片中来选举。也就是把FCKEditor的“浏览”按钮，抽取出来。<br /><div align="center">文/陈刚 <a title="http://www.blogjava.net/chengang/archive/2007/09/26/148114.html" href="/chengang/archive/2007/09/26/148114.html">www.chengang.com.cn</a> 转载请保留出处<br /></div>在阅读FCKEditor的源码之后，做如下处理。<br /><br />1. 新增两个javascript函数。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> currentImageTextID;<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">FCKEditor的文件浏览窗关闭后，会调用此函数，并把所选图片的url传入。</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> SetUrl(url){<br />  document.getElementById(currentImageTextID).value</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">url;<br />}<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">imageTextID: 图片文本框的ID值</span><span style="color: rgb(0, 128, 0);"><br />//</span><span style="color: rgb(0, 128, 0);">uploadPath: 服务器的图片目录</span><span style="color: rgb(0, 128, 0);"><br />//</span><span style="color: rgb(0, 128, 0);">type: 浏览类型，值可为Image/Flash/File/Media，如果为空字串，则表示浏览所有类型的文件</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> OpenImageBrowser(imageTextID, uploadPath, type ) {<br />  currentImageTextID </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> imageTextID;<br />  window.open('</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">javascripts</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">fckeditor</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">editor</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">filemanager</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">browser</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 255);">default</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">browser.html</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);">uploaded</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">uploadPath</span><span style="color: rgb(0, 0, 0);"> +</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">Type</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">type</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">Connector</span><span style="color: rgb(0, 0, 0);">=/</span><span style="color: rgb(0, 0, 0);">fckeditor</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">command','Browse</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">Upload Images','toolbar</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">no,status</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">no, resizable</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">yes,dependent</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">yes, scrollbars</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">yes,width</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">600</span><span style="color: rgb(0, 0, 0);">,height</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">400</span><span style="color: rgb(0, 0, 0);">')<br />}<br /></span></div><br />2.在View中这样使用<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">标志图片:</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"><br />&lt;</span><span style="color: rgb(0, 0, 0);">input id</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">topic_image</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> name</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">topic[image]</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> size</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">30</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> type</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">text</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;<br />&lt;</span><span style="color: rgb(0, 0, 0);">input value</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">浏览服务器</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> onclick</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">OpenImageBrowser('topic_image', '/uploads/s&lt;%= params[:user_id]%&gt;', 'Image')</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> type</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">button</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span></div><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><br /><br /><img src ="http://www.blogjava.net/chengang/aggbug/148412.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2007-09-26 18:49 <a href="http://www.blogjava.net/chengang/archive/2007/09/26/148412.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>让Rails版的FCKEditor支持动态设置上传目录</title><link>http://www.blogjava.net/chengang/archive/2007/09/26/148114.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Wed, 26 Sep 2007 02:13:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2007/09/26/148114.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/148114.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2007/09/26/148114.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/148114.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/148114.html</trackback:ping><description><![CDATA[一个多用户的系统，上传图像文件等，希望不同用户的图像上传到它专有的目录里。我最初查到在PHP版的FCKEditor是通过设置$Config('UserFilesPath')来实现，但Rails版的FCKEditor没有此项设置（搜索UserFilesPath关键字后做出此判断）。接着，我查看了FCKEditor关键的fckeditor_controller.rb的源代码，似乎它并不支持此项设置。再看javaeye是怎么用FCKEditor的，发现它放弃了FCKEditor的上传功能。google了半天，除了那些转来转去的相同内容的帖子之外（搞不懂有了google之后，怎么还会有人费劲去转帖别人的文章），一点营养也没有。在JavaEye发了个求助帖，没人理 :-( 。 传说中高手云集的JavaEye，其Rails版块真是冷清，给人阴飕飕的感觉。没办法，自己改源代码吧。<br /><div align="center">文/陈刚 <a title="http://www.blogjava.net/chengang/archive/2007/09/26/148114.html" href="/chengang/archive/2007/09/26/148114.html">www.chengang.com.cn</a> 转载请保留出处<br /></div>1.修改fckeditor_controller.rb，把它那几个private方法修改如下：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">  <br />  </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"><br />  def current_directory_path<br />    base_dir </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">#{RAILS_ROOT}/public</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /><br />    #TODO 在创建用户时，就建立好目录。这时可以去掉这部份代码，提高运行效率。<br />    (</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">#{params[:uploaded]||UPLOADED}/#{params[:Type]}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).split(</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">).each </span><span style="color: rgb(0, 0, 255);">do</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">s</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"><br />    next </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> s</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">''</span><span style="color: rgb(0, 0, 0);"><br />        base_dir </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> s<br />        Dir.mkdir(base_dir,</span><span style="color: rgb(0, 0, 0);">0775</span><span style="color: rgb(0, 0, 0);">) unless File.exists</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);">(base_dir)<br />    end<br />    <br />    check_path(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">#{base_dir}#{params[:CurrentFolder]}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />  end<br />  <br />  def upload_directory_path<br />    uploaded </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> @request.relative_url_root.to_s</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">#{params[:uploaded]||UPLOADED}/#{params[:Type]}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">#{uploaded}#{params[:CurrentFolder]}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />  end<br />  <br />  def check_file(file)<br />    # check that the file is a tempfile object<br />    unless </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">#{file.class}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Tempfile</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">#{file.class}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">StringIO</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />      @errorNumber </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">403</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> Exception.</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"><br />    end<br />    file<br />  end<br />  <br />  def check_path(path)<br />    exp_path </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> File.expand_path path<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> exp_path </span><span style="color: rgb(0, 0, 0);">!~</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">r[</span><span style="color: rgb(0, 0, 0);">^</span><span style="color: rgb(0, 0, 0);">#{File.expand_path(RAILS_ROOT)}</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">#{params[:uploaded]</span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);">UPLOADED}]<br />      @errorNumber </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">403</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> Exception.</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"><br />    end<br />    path<br />  end</span></div><br />另外，它前面的常量UPLOADED_ROOT也没用了，可以删掉。<br /><br /><br />2. 在上面的代码中<span style="color: rgb(0, 0, 0);">params[:uploaded]是关键，它就是我们动态定义的上传目录。该值来自于FCKEditor的一些html页面，它是通过get参数传入的。修改browser.html文件（如下粗体部份），在它的url请求中把我们定义目录加入到get参数列中，这样它就可以传到</span>fckeditor_controller.rb里了<span style="color: rgb(0, 0, 0);">。<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"><br />var sServerPath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> GetUrlParam( </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">ServerPath</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> ) ;<br /></span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( sServerPath.length </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> )<br />    oConnector.ConnectorUrl </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">ServerPath=</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> escape( sServerPath ) </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> ;<br /><br /><b>var sUploaded </b></span><b><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> GetUrlParam( </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">uploaded</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> ) ;<br /></span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( sUploaded.length </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> )<br />    oConnector.ConnectorUrl </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">uploaded=</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> escape( sUploaded ) </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">'</span></b><span style="color: rgb(0, 0, 0);"><b> ;</b><br /><br />oConnector.ResourceType        </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> GetUrlParam( </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">Type</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> ) ;<br />oConnector.ShowAllTypes        </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ( oConnector.ResourceType.length </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ) ;<br /><br /></span></div><br />3.  上面</span>的GetUrlParam( 'uploaded' ) 的值来自于fckcustom.js。修改fckcustom.js（如下粗体部份），把uploaded加入到get参数列中。<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">//</span><span style="color: rgb(0, 0, 0);"> CHANGE FOR APPS HOSTED IN SUBDIRECTORY<br />FCKRelativePath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">''</span><span style="color: rgb(0, 0, 0);">;<br /><br /></span><span style="color: rgb(0, 0, 0);">//</span><span style="color: rgb(0, 0, 0);"> DON</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">T CHANGE THESE</span><span style="color: rgb(128, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">FCKConfig.LinkBrowserURL </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> FCKConfig.BasePath </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">filemanager/browser/default/browser.html?Connector=</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">FCKRelativePath</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/fckeditor/command</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br />FCKConfig.ImageBrowserURL </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> FCKConfig.BasePath </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">filemanager/browser/default/browser.html?<b>uploaded=</b></span><b><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">FCKConfig.uploaded</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(128, 0, 0);">'</span></b><span style="color: rgb(128, 0, 0);"><b>&amp;</b>Type=Image&amp;Connector=</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">FCKRelativePath</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/fckeditor/command</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br />FCKConfig.FlashBrowserURL </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> FCKConfig.BasePath </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">filemanager/browser/default/browser.html?<b>uploaded=</b></span><b><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">FCKConfig.uploaded</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(128, 0, 0);">'</span></b><span style="color: rgb(128, 0, 0);"><b>&amp;</b>Type=Flash&amp;Connector=</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">FCKRelativePath</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/fckeditor/command</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br /><br />FCKConfig.LinkUploadURL </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> FCKRelativePath</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/fckeditor/upload</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br />FCKConfig.ImageUploadURL </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> FCKRelativePath</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/fckeditor/upload?Type=Image<b>&amp;uploaded=</b></span><b><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span></b><span style="color: rgb(0, 0, 0);"><b>FCKConfig.uploaded</b>;<br />FCKConfig.FlashUploadURL </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> FCKRelativePath</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/fckeditor/upload?Type=Flash<b>&amp;uploaded=</b></span><b><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span></b><span style="color: rgb(0, 0, 0);"><b>FCKConfig.uploaded</b>;<br />FCKConfig.AllowQueryStringDebug </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> false;<br />FCKConfig.SpellChecker </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">SpellerPages</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br /><br /></span><span style="color: rgb(0, 0, 0);">//</span><span style="color: rgb(0, 0, 0);"> ONLY CHANGE BELOW HERE<br />FCKConfig.SkinPath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> FCKConfig.BasePath </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">skins/silver/</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br />FCKConfig.AutoDetectLanguage </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> false ;<br />FCKConfig.DefaultLanguage </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">zh-cn</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> ;<br />FCKConfig.FontNames </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">微软雅黑;宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> ;<br /><br />FCKConfig.ToolbarSets[</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Simple</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [<br />    [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Source</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">-</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">FitWindow</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Preview</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">-</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Templates</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">],<br />    [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">PasteText</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">PasteWord</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">],<br />    [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Undo</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Redo</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Find</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Replace</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">],<br />    </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,<br />    [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">RemoveFormat</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Bold</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Italic</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Underline</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">StrikeThrough</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">],<br />    [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">OrderedList</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">UnorderedList</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Outdent</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Indent</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">],<br />    [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">JustifyLeft</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">JustifyCenter</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">JustifyRight</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">JustifyFull</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">],<br />        [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">TextColor</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">BGColor</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">],<br />    [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Link</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Unlink</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Anchor</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">],<br />    [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Image</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Flash</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Table</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Rule</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Smiley</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">],<br />    </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,<br />    [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Style</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">FontFormat</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">FontName</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">FontSize</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">]<br />] ;<br /></span></div><br />4. 上面FCKConfig.uploaded的值来自于fckeditor.rb。在fckeditor.rb中加入一句（如下粗体所示）。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">      javascript_tag( </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">var oFCKeditor = new FCKeditor('#{id}', '#{width}', '#{height}', '#{toolbarSet}');\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"><br />                      </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">oFCKeditor.BasePath = \</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">{base_path}\"\n"+</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                      </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">oFCKeditor.Config['CustomConfigurationsPath'] = '../../fckcustom.js';\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"><br /><b>                      </b></span><b><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">oFCKeditor.Config['uploaded'] = '#{options[:path]}';\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span></b><span style="color: rgb(0, 0, 0);"><br />                      </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">oFCKeditor.ReplaceTextarea();\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)                         <br /></span></div><br />5.<b><span style="color: rgb(0, 0, 0);"></span></b>不过上面oFCKeditor.Config['uploaded']的值要传到fckcustom.js的FCKConfig.uploaded里，还需要修改fckeditorcode_gecko.js和fckeditorcode_ie.js（这两个文件对javascript进行了压缩处理，修改起来较难操作）。我是参考了oFCKeditor.Config['CustomConfigurationsPath'] 这个参数的载入实现，才找到这种鸟不生蛋的地方。搜索这两个文件的关键字<span style="color: rgb(0, 0, 0);">CustomConfigurationsPath</span>，找到如下一行，然后加入一个else if判断(如下粗体所示）。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (D</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">CustomConfigurationsPath</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">) FCKConfig[D]</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">E;</span><b><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (D</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">uploaded</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">) FCKConfig[D]</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">E;</span></b><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (E.toLowerCase()</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">true</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.PageConfig[D]</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;</span></div><br /><span style="color: rgb(0, 0, 0);"></span><br />6.最后在fckeditor.rb里的#{options[:path]}来自于我们前台的view了。如下粗体所示，把标准的fckedit<span style="color: rgb(0, 0, 0);">or_textarea新增加了一个参数，其中</span><span style="color: rgb(0, 0, 0);">params[:user_id]是把</span><span style="color: rgb(0, 0, 0);">用户的ID值做为</span><span style="color: rgb(0, 0, 0);">目录名。这样就实现了动态改变FCKEditor的上传目录。</span><br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">&lt;%=</span><span style="color: rgb(0, 0, 0);">fckeditor_textarea(:topic, :content, :ajax </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">, :toolbarSet </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">Simple</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, :height </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">400px</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,  :path </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/uploads/#{params[:user_id]}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 0);">%&gt;</span></div><br /><br />修改完后需要重启WEB服务，最后别忘记把public/javascripts/fckeditor和vendor/plugins/fckeditor/public/javascripts同步一下，原因见http://www.blogjava.net/chengang/archive/2007/09/24/147867.html<span style="color: rgb(0, 0, 0);"><b><br /></b></span><img src ="http://www.blogjava.net/chengang/aggbug/148114.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2007-09-26 10:13 <a href="http://www.blogjava.net/chengang/archive/2007/09/26/148114.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>定制FCKEditor，以及使其中文化</title><link>http://www.blogjava.net/chengang/archive/2007/09/24/147867.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Mon, 24 Sep 2007 10:24:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2007/09/24/147867.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/147867.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2007/09/24/147867.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/147867.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/147867.html</trackback:ping><description><![CDATA[安装完FCKEditor还是不够的，首先就面临两个任务：（1）将它中文化。（2）有些功能不需要的，就需要把它去掉。FCKEditor在这方面做得很好，其可定制性相当强。<br /><div align="center">文/陈刚  <a title="www.chengang.com.cn" href="www.chengang.com.cn">www.chengang.com.cn</a><br /></div>首先，我们来看看FCKEditor在Rails中的运行特性，其插件主要是安装在vendor/plugins/fckeditor。主要的代码在vendor/plugins/fckeditor/public/javascripts，其中fckcustom.js是配置文件，另外更深一层的子目录fckeditor中还有一个fckconfig.js也是配置文件。fckcustom.js配置的优先顺序大于fckconfig.js，因此一般修改fckcustom.js就可以了，不必去动fckconfig.js。<br /><br />在启动WEBrick( ruby script/server)时，会自动把vendor/plugins/fckeditor/public/javascripts的内容复制到public/javascripts目录。因此如果你修改了FCKEditor的配置文件之后，需要把复制到public/javascripts目录的FCKEditor相关文件删除掉，然后再重启WEBrick。当然，你也可以直接修改public/javascripts目录的FCKEditor的缓存的配置文件，这样不必重启WEBrick，就可以立即看到修改效果。不过建议你在完成修改后，同时也要更新vendor/plugins/fckeditor/public/javascripts下的配置文件，毕竟public/javascripts里的应该算是临时文件。<br /><br /><br />1.中文化<br /><br />在fckcustom.js里加入两项（粗体显示）<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">FCKConfig</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">SkinPath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> FCKConfig</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">BasePath </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">skins/silver/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">;<br /><b><font color="#ff0000">FCKConfig</font></b></span><font color="#000000"><b><font color="#ff0000"><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">AutoDetectLanguage </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> false ;<br />FCKConfig</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">DefaultLanguage </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">zh-cn</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span></font></b><span style="color: rgb(0, 0, 0);"><b><font color="#ff0000"> </font>;</b><br /></span></font></div><br />2. 定制FCKEditor的工具栏<br />修改fckcustom.js里的如下项目，增删改自便。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">FCKConfig</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">ToolbarSets[</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">Simple</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [   。。。 。。。<br /></span></div><br />这里要注意一点，有些网上文章把<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">toolbarSet写成了</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">toolbarKit，这是错误的。如果你发现对工具栏的配置不起作用，那么要检查一下。正确的写法如下：<br /></span><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">&lt;%=</span><span style="color: rgb(0, 0, 0);">fckeditor_textarea(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">topic</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">content</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">ajax </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> true</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">toolbarSet </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">Simple</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">width </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">100%</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">height </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">300px</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><br /><br /><br /><br /><br /><img src ="http://www.blogjava.net/chengang/aggbug/147867.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2007-09-24 18:24 <a href="http://www.blogjava.net/chengang/archive/2007/09/24/147867.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>error_messages_for的中文化</title><link>http://www.blogjava.net/chengang/archive/2007/09/19/146548.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Wed, 19 Sep 2007 09:35:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2007/09/19/146548.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/146548.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2007/09/19/146548.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/146548.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/146548.html</trackback:ping><description><![CDATA[在Rails中error_messages_for为国际化的考虑不是很周全，它显示的是模型的字段名称，这对于用户来说是不友好的。为了解决这个问题，只能改它的源码了----将如下方法，放入<span style="color: rgb(0, 0, 0);">ApplicationHelper<br /></span><div align="center"><span style="color: rgb(0, 0, 0);">文/陈刚  www.chengang.com.cn  转载请声明出处</span><span style="color: rgb(0, 0, 0);"></span></div><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">  def error_messages_for(</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">params)<br />    </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">add by glchengang</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    key_hash </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {}<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> params</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">first</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">is_a</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);">(Hash)<br />      key_hash </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  params</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">first<br />      params</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">delete_at(</span><span style="color: rgb(128, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />    end<br />    </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">add end</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />    options </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> params</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">last</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">is_a</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);">(Hash) </span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"> params</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">pop</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">symbolize_keys </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);"> {}<br />    objects </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> params</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">collect {</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">object_name</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"> instance_variable_get(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">@#{object_name}</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">) }</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">compact<br />    count   </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> objects</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">inject(</span><span style="color: rgb(128, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">) {</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">sum</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> object</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"> sum </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> object</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">errors</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">count }<br />    </span><span style="color: rgb(0, 0, 255);">unless</span><span style="color: rgb(0, 0, 0);"> count</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">zero</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"><br />      html </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {}<br />      [</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">id</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">class]</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">each</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">do</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">key</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> options</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">include</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);">(key)<br />          value </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> options[key]<br />          html[key] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> value </span><span style="color: rgb(0, 0, 255);">unless</span><span style="color: rgb(0, 0, 0);"> value</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">blank</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />          html[key] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">errorExplanation</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);"><br />        end<br />      end<br />      </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> change by glchengang</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">      header_message </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">有#{count}个错误</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">       header_message = "#{pluralize(count, 'error')} prohibited this #{(options[:object_name] || params.first).to_s.gsub('_', ' ')} from being saved"<br />      <br />      #add by glchengang</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">      error_messages </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> objects</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">map</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">do</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">object</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"><br />        temp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> []<br />        object</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">errors</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 255);">each</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">do</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">attr</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> msg</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"><br />          temp </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> content_tag(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">li</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> (key_hash[attr] </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"> attr) </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> msg) <br />        end<br />        temp<br />      end<br />      </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">add end<br /><br />#        error_messages = objects.map {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } }</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">      content_tag(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">div</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"><br />        content_tag(options[</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">header_tag] </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">h2</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> header_message) </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">           content_tag(:p, 'There were problems with the following fields:') &lt;&lt;</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">          content_tag(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">ul</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> error_messages)</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"><br />        html<br />      )<br />    </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 0); font-weight: bold;">''</span><span style="color: rgb(0, 0, 0);"><br />    end<br />  end</span></div><br /><br />使用依然兼容老的方式，你也可以传入一个哈希表，把模型字段显示成对应的中文，示例如下：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">&lt;%=</span><span style="color: rgb(0, 0, 0);"> <br />h </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">username</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">用户名</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">password</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">密码</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">}<br />error_messages_for h</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">user<br /></span><span style="color: rgb(0, 0, 0);">%&gt;</span></div><br /><p>另外，还要在environment.rb的最后插入以下代码：
<br /></p><p></p><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">errors </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ActiveRecord</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Errors</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">default_error_messages<br />errors[</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">taken] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">已经被使用</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);"><br />errors[</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">blank] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">不能为空</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span></div><br /><img src ="http://www.blogjava.net/chengang/aggbug/146548.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2007-09-19 17:35 <a href="http://www.blogjava.net/chengang/archive/2007/09/19/146548.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>让will_paginate的分页支持ajax</title><link>http://www.blogjava.net/chengang/archive/2007/09/02/142077.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Sun, 02 Sep 2007 07:42:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2007/09/02/142077.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/142077.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2007/09/02/142077.html#Feedback</comments><slash:comments>14</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/142077.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/142077.html</trackback:ping><description><![CDATA[关于will_paginate插件，请看这个帖子: http://mmm.javaeye.com/blog/116931。<br /><div align="center">文/陈刚 (www.chengang.com.cn)<br /></div>
但一直搜不到它支持ajax分面的方法 ，于是我参考它分页方法的源代码(位于:vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb)，稍微改写，变成了一个支持ajax的分页方法。以下代码复制到application_helper里即可。<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 0);"><br />
  </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">-----------------------------------------</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> will_paginate插件的ajax分页</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">-----------------------------------------</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">  @@pagination_options </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> { </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">pagination</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"><br />
        </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">prev_label   </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">上一页</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"><br />
        </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">next_label   </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">下一页</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"><br />
        </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">inner_window </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> links around the current page</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">outer_window </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> links around beginning and end</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">separator    </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> single space is friendly to spiders and non-graphic browsers</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">param_name   </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">page</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"><br />
        </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">add by chengang</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">update </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">nil</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">ajax所要更新的html元素的id</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">url_suffix </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">''</span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">url的后缀，主要是为了补全REST所需要的url</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">add end</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        }<br />
  mattr_reader </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">pagination_options<br /><br />
  def will_paginate_remote(entries </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> @entries</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> options </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {})<br />
    total_pages </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> entries</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">page_count<br /><br />
    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> total_pages </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"><br />
      options </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> options</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">symbolize_keys</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">reverse_merge(pagination_options)<br />
      page</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> param </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> entries</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">current_page</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> options</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">delete(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">param_name)<br />
      <br />
      inner_window</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> outer_window </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> options</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">delete(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">inner_window)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">to_i</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> options</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">delete(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">outer_window)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">to_i<br />
      </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">add by chengang</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">      update </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  options</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">delete(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">update)<br />
      suffix </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  options</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">delete(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">url_suffix)<br />
      url </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> request</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">env[</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">PATH_INFO</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">] <br />
      url </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> suffix </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> suffix<br />
      </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">add end</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />
      </span><span style="color: rgb(0, 128, 128);">min</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> page </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> inner_window<br />
      </span><span style="color: rgb(0, 128, 128);">max</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> page </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> inner_window<br />
      </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">max</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> total_pages then </span><span style="color: rgb(0, 128, 128);">min</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">max</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> total_pages<br />
      elsif </span><span style="color: rgb(0, 128, 128);">min</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">  then </span><span style="color: rgb(0, 128, 128);">max</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">min</span><span style="color: rgb(0, 0, 0);"><br />
      </span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
      <br />
      </span><span style="color: rgb(0, 128, 128);">current</span><span style="color: rgb(0, 0, 0);">   </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">min</span><span style="color: rgb(0, 0, 0);">..</span><span style="color: rgb(0, 128, 128);">max</span><span style="color: rgb(0, 0, 0);"><br />
      beginning </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">..</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> outer_window)<br />
      tail      </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (total_pages </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> outer_window)</span><span style="color: rgb(0, 0, 0);">..</span><span style="color: rgb(0, 0, 0);">total_pages<br />
      visible   </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [beginning</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">current</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> tail]</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">map(</span><span style="color: rgb(0, 0, 0);">&amp;:</span><span style="color: rgb(0, 0, 0);">to_a)</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">flatten</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 128, 128);">sort</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">uniq<br />
      links</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">prev</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> []</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"><br /><br />
      visible</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 128, 128);">each</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">do</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">n</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"><br />
        </span><span style="color: rgb(0, 128, 128);">next</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> n </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"><br />
        </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> n </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> total_pages<br /><br />
        unless n </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">prev</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"><br />
          </span><span style="color: rgb(0, 128, 128);">prev</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> n<br />
          </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">change by chengang</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">          text </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (n</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">page </span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"> n </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">[#{n}]</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />
          links </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> page_link_remote_or_span((n </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> page </span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"> n </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);"> nil)</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">current</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> text</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> param</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> update</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> url)<br />
        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />
          </span><span style="color: rgb(0, 128, 128);">prev</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> n </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"><br />
          links </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><img src="http://www.blogjava.net/images/dot.gif" alt="" /></span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />
          redo<br />
        </span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
      </span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
      <br />
      </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">change by chengang</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">      links</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">unshift page_link_remote_or_span(entries</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">previous_page</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">disabled</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> options</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">delete(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">prev_label)</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> param</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> update</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> url)<br />
      links</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">push    page_link_remote_or_span(entries</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">next_page</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">disabled</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> options</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">delete(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">next_label)</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> param</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> update</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> url)<br />
      </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">change end</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />
      content_tag </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">div</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> links</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 128, 128);">join</span><span style="color: rgb(0, 0, 0);">(options</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">delete(</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">separator))</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> options<br />
    </span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
  </span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
  <br /></span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"><br /><br />
  def page_link_remote_or_span(page</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> span_class</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> text</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> param</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> update</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> url)<br />
    unless page<br />
      content_tag </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">span</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> text</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> span_class<br />
    </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />
      link_to_remote text</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">update </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> update</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">url </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">#{url}?#{param.to_sym}=#{page}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">method</span><span style="color: rgb(0, 0, 0);">=&gt;:</span><span style="color: rgb(0, 0, 0);">get<br />
    </span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br />
  </span><span style="color: rgb(0, 128, 128);">end</span><span style="color: rgb(0, 0, 0);"><br /><br /></span></div><br />
在view中的使用如下所示:<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 0);">          </span><span style="color: rgb(0, 0, 0);">&lt;%=</span><span style="color: rgb(0, 0, 0);">will_paginate_remote @topics</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">update </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">topicList</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">url_suffix </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> url_suffix</span><span style="color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><br /><img src ="http://www.blogjava.net/chengang/aggbug/142077.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2007-09-02 15:42 <a href="http://www.blogjava.net/chengang/archive/2007/09/02/142077.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在Rails中使用FCKeditor插件实现WEB富文本编辑</title><link>http://www.blogjava.net/chengang/archive/2007/08/25/139287.html</link><dc:creator>陈刚</dc:creator><author>陈刚</author><pubDate>Sat, 25 Aug 2007 08:44:00 GMT</pubDate><guid>http://www.blogjava.net/chengang/archive/2007/08/25/139287.html</guid><wfw:comment>http://www.blogjava.net/chengang/comments/139287.html</wfw:comment><comments>http://www.blogjava.net/chengang/archive/2007/08/25/139287.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/chengang/comments/commentRss/139287.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chengang/services/trackbacks/139287.html</trackback:ping><description><![CDATA[比如象BlogJava这里编辑器就应该是用的FCKeditor
，FCKeditor 相当有名，它有PHP、JSP、rails等多个版本，核心都是一些javascript代码。<br /><br /><div style="text-align: center;">文/陈刚  (www.chengang.com.cn)<br /></div><br />环境：ubuntu linux 7.0.4  +  ruby 1.8.5 + Rails 1.2.3 + FCKeditor 0.4.1
<br /><br />直接从它的subversion库里取得该Rails插件。先进入到你的项目根目录，再执行如下命令<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->ruby script/plugin install svn://rubyforge.org/var/svn/fckeditorp/trunk/fckeditor<br /></div><br />其他说明：<br />(1)你的linux必须先安装了subversion。（ubuntu里用新立得搜subversion即得）<br />(2)把命令中的install 改为 destory，可以删除安装。<br />(3)我取到的是2007年4月份最后更新的, v 0.4.1版<br />(4)FCKeditor安装在项目根目录下的vendor/plugins/fckeditor
里，<br />(5)vendor/plugins/fckeditor里的README很值得一读，我碰到Ajax问题，查了所以网上的中文资料都没有提到，在这个README却有。<br /><br /><br />用如下语句在页面里含入它的javascript库<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">&lt;%=</span><span style="color: rgb(0, 0, 0);"> javascript_include_tag :fckeditor </span><span style="color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);">  </span></div>
或<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">&lt;%=</span><span style="color: rgb(0, 0, 0);"> javascript_include_tag </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">fckeditor/fckeditor</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><br />在需要富文本的Form表单用如下语句生成一个富文件编辑框：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">&lt;%=</span><span style="color: rgb(0, 0, 0);"> fckeditor_textarea(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">topic</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">content</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, :toolbarSet </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> 'Simple', :width </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> '</span><span style="color: rgb(0, 0, 0);">100</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">', :height </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> '200px') </span><span style="color: rgb(0, 0, 0);">%&gt;</span></div><br />说明：topic对应模型对象,content对应它的字段。也就是要求当前页要有@topic这个实例变量。<br /><br /><br />如果是用了ajax，则需要在form_remote_tag加上一个before项<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 0);">&lt;%=</span><span style="color: rgb(0, 0, 0);"> form_remote_tag(:update </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> update,<br />                     <span style="color: red;"> :before </span></span><span style="color: red;">=&gt;</span><span style="color: rgb(0, 0, 0);"><span style="color: red;"> fckeditor_before_js('topic', 'content'),</span><br />                      :url </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> {:controller </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> 'topics', :action </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> 'create', :template </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> 'show'} )</span><span style="color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br />并且富文件编辑框要加一个ajax=true的选项：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">&lt;%=</span><span style="color: rgb(0, 0, 0);"> fckeditor_textarea(:topic, :content, <span style="color: red;">:ajax </span></span><span style="color: red;">=&gt; true</span><span style="color: rgb(0, 0, 0);"><span style="color: red;">, </span>:toolbarKit </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> 'Simple', :width </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> '</span><span style="color: rgb(0, 0, 0);">100</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">', :height </span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);"> '600px') </span><span style="color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><br /><br /><br /><br />在使上传图片的功能时碰到了错误。弹出出alert对话框，显示：Error on file upload.Error number: 403
<br /><p>在日志里显示如下，表面上看好象是路由配置的问题</p><p>ActionController::RoutingError (no route found to match "/fckblank.html" with {:method=&gt;:get}):
<br />    /var/lib/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1292:in `recognize_path'
<br />    /var/lib/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1282:in `recognize'
<br />    /var/lib/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:40:in `dispatch'
<br />    /var/lib/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:113:in `handle_dispatch'
<br />    /var/lib/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in `service'
<br />    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
<br />    /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
<br />    /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
<br />    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
<br />    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'</p><br />最后在http://blog.caronsoftware.com/articles/2006/12/03/fckeditor-0-4-0-released#comment-1745找到了答案，这是一个BUG
<p>解决方法 ：<br /></p><p>修改：vendor/plugins/fckeditor/app/controller/fckeditor_controller.rb<br />将原来的<br /></p><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">unless</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">#{file.class}</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">Tempfile</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span></div><br />改为<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">unless</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">#{file.class}</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">Tempfile</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">#{file.class}</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">StringIO</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span></div><br /><br /><br /><img src ="http://www.blogjava.net/chengang/aggbug/139287.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chengang/" target="_blank">陈刚</a> 2007-08-25 16:44 <a href="http://www.blogjava.net/chengang/archive/2007/08/25/139287.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>