??xml version="1.0" encoding="utf-8" standalone="yes"?>香蕉视频在线观看网站,国产精品久久综合,精品视频在线免费http://www.aygfsteel.com/chengang/archive/2017/12/29/432993.html陈刚陈刚Fri, 29 Dec 2017 07:37:00 GMThttp://www.aygfsteel.com/chengang/archive/2017/12/29/432993.htmlhttp://www.aygfsteel.com/chengang/comments/432993.htmlhttp://www.aygfsteel.com/chengang/archive/2017/12/29/432993.html#Feedback0http://www.aygfsteel.com/chengang/comments/commentRss/432993.htmlhttp://www.aygfsteel.com/chengang/services/trackbacks/432993.html我的新博客地址Q?nbsp;yowob.cn

书的软g和代码放在百度网盘:https://pan.baidu.com/s/1kVb31aR




陈刚 2017-12-29 15:37 发表评论
]]>
二域名的java实现http://www.aygfsteel.com/chengang/archive/2010/12/29/341939.html陈刚陈刚Wed, 29 Dec 2010 15:19:00 GMThttp://www.aygfsteel.com/chengang/archive/2010/12/29/341939.htmlhttp://www.aygfsteel.com/chengang/comments/341939.htmlhttp://www.aygfsteel.com/chengang/archive/2010/12/29/341939.html#Feedback0http://www.aygfsteel.com/chengang/comments/commentRss/341939.htmlhttp://www.aygfsteel.com/chengang/services/trackbacks/341939.htmlhttp://www.yowob.com )Q其他涉及到为用h供一个二U域名功能,实现Ҏ(gu)如下Q?br />
(1)首先要在域名服务商端做一个泛域名解析. 我用的是godaddy.com,新Z个A记录(host=*,point to指向我的服务器的ip),q样所有二U域名都会{到我的服务器来了

(2)接着在web.xml配一个自已写的域名过滤器,

    <filter>
        <filter-name>URLFilter</filter-name>
        <filter-class>com.yowob.commons.URLFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>URLFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

qo器的代码如下。这里先二U域名和全球域名和用户ID的映?保存在一个数据表? 然后讉Kq来时对地址做一个判? 再取出对应的用户ID. 再{一下就行了. 我的静态文仉在static目录Q所以还加了一个static的判断?br /> 比如: http://time.you.com/board/21 用time对应用户ID?,则访问效果有 http://www.you.com/6/board/21相同, 不过地址栏还是显C?a >http://time.you.com/board/21?br /> 再比如:htttp://www.userdomain.com/board/21Q这个是用户ID?的全球域名,讉K效果也和上面一栗?br />
package com.yowob.commons;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.yowob.Constants;
import com.yowob.dao.SiteDAO;
import com.yowob.dto.SiteDTO;

public class URLFilter implements Filter {
    
private static final Log log = LogFactory.getLog(URLFilter.class);
    
private static final String DOMAIN_END = "." + Constants.DOMAIN; //.you.com
    private static final Map<String, Long> NAME_MAP = new HashMap<String, Long>();
    
private static final Map<String, Long> DOMAIN_MAP = new HashMap<String, Long>();

    @Override
    
public void init(FilterConfig filterConfig) throws ServletException {
        log.info(
"------------------------------init");
        SiteDAO siteDAO 
= new SiteDAO();
        List
<SiteDTO> list = siteDAO.getAll();
        
for (SiteDTO siteDTO : list) {
            String name 
= siteDTO.getName();
            
if (StringUtils.isNotEmpty(name)) {
                NAME_MAP.put(name, siteDTO.getId());
            }
            String domain 
= siteDTO.getDomain();
            
if (StringUtils.isNotEmpty(domain)) {
                DOMAIN_MAP.put(domain, siteDTO.getId());
            }
        }
    }

    
public static void updateName(String oldValue, String newValue, Long siteId) {
        
if (StringUtils.equals(oldValue, newValue)) {
            
return;
        }
        
if (StringUtils.isNotEmpty(oldValue)) {
            NAME_MAP.remove(oldValue);
        }
        
if (StringUtils.isNotEmpty(newValue)) {
            NAME_MAP.put(newValue, siteId);
        }
    }

    
public static void updateDomain(String oldValue, String newValue, Long siteId) {
        
if (StringUtils.equals(oldValue, newValue)) {
            
return;
        }
        
if (StringUtils.isNotEmpty(oldValue)) {
            DOMAIN_MAP.remove(oldValue);
        }
        
if (StringUtils.isNotEmpty(newValue)) {
            DOMAIN_MAP.put(newValue, siteId);
        }
    }

    @Override
    
public void destroy() {
        log.info(
"------------------------------destroy");
    }

    @Override
    
public void doFilter(ServletRequest servletRequest, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request 
= (HttpServletRequest) servletRequest;
        String requestURI 
= request.getRequestURI();
        String serverName 
= request.getServerName().toLowerCase();
        String realURI 
= getRealRequestURI(serverName, requestURI);
        request.getRequestDispatcher(realURI).forward(request, response);
    }

    
private String getRealRequestURI(String serverName, String requestURI) {
        
if (Constants.WWW_DOMAIN.equals(serverName) || requestURI.startsWith("/static/"|| Constants.DOMAIN.equals(serverName)) {
            
return requestURI;
        }
        
if (serverName.endsWith(DOMAIN_END)) {
            String secondDomain 
= serverName.substring(0, serverName.indexOf("."));
            
//|站id
            if (NumberUtils.isNumber(secondDomain))
                
return getURI(secondDomain, requestURI);
            
//|站英文?/span>
            Long siteId = NAME_MAP.get(secondDomain);
            
if (siteId == null) {
                
//保留的二U域?/span>
                if (Constants.isPrivateSecondDomain(secondDomain)) {
                    
return requestURI;
                }
                
return "/message?msg=不存在二U域?/span>" + secondDomain;
                
//                throw new RuntimeException("do not exist second domain: " + secondDomain);
            }
            
return getURI(siteId + "", requestURI);
        }
        
//域名
        Long siteId = DOMAIN_MAP.get(serverName);
        
if (siteId == null) {
            
return requestURI;
        } 
else {
            
return getURI(siteId + "", requestURI);
        }
    }

    
private static String getURI(String siteId, String requestURI) {
        
if (requestURI.equals("/")) {
            
return "/" + siteId;
        } 
else {
            
return "/" + siteId + requestURI;
        }
    }

}


其他一些小技巧:
Q1Qؓ了便于本机测试,可以修改windows 的hosts文g。我的如下:
127.0.0.1       localhost
127.0.0.1       you.com
127.0.0.1       www.you.com
127.0.0.1       time1.you.com
127.0.0.1       time2.you.com
127.0.0.1       6.you.com
127.0.0.1       www.bobo.com

Q2Qweb늚各种地址则要注意相对路径的问题。主要考虑
首先讄<base />Q或<base />其中地址最后要加一?
然后面中其他地址前面不加/Q就是相对地址Q以地址栏ؓ基础Q。加?Q则是绝对地址?br />

陈刚 2010-12-29 23:19 发表评论
]]>
VIM的常用插?配置文g+资料http://www.aygfsteel.com/chengang/archive/2007/10/18/153970.html陈刚陈刚Thu, 18 Oct 2007 10:15:00 GMThttp://www.aygfsteel.com/chengang/archive/2007/10/18/153970.htmlhttp://www.aygfsteel.com/chengang/comments/153970.htmlhttp://www.aygfsteel.com/chengang/archive/2007/10/18/153970.html#Feedback7http://www.aygfsteel.com/chengang/comments/commentRss/153970.htmlhttp://www.aygfsteel.com/chengang/services/trackbacks/153970.html 我把VIM的常用插Ӟ自己用的配置文gQ收|的一些资料一q打包了Q省得初用VIM的h找来扑֎费旉?br />
http://www.aygfsteel.com/Files/chengang/myvim.zip



在ubuntu7.10中的gvim出现qQ这旉要在ȝ录下的?vimrc”文件中加上定义字体的一句。我用的是“微软雅黑”字体所以此句ؓQ?br />
set guifont=YaHei\ Consolas\ Hybrid\ 10
注意Q字体名中有I格的,用斜杠分开Q而且斜杠后面一定要有一个空根{?0是字体大,前面有一个空根{?br />

陈刚 2007-10-18 18:15 发表评论
]]>
个性化面布局的设计思考与Rails初步实现http://www.aygfsteel.com/chengang/archive/2007/10/11/151900.html陈刚陈刚Wed, 10 Oct 2007 16:00:00 GMThttp://www.aygfsteel.com/chengang/archive/2007/10/11/151900.htmlhttp://www.aygfsteel.com/chengang/comments/151900.htmlhttp://www.aygfsteel.com/chengang/archive/2007/10/11/151900.html#Feedback0http://www.aygfsteel.com/chengang/comments/commentRss/151900.htmlhttp://www.aygfsteel.com/chengang/services/trackbacks/151900.html
q个设计其实很简单,是“引?配置?-M面只定义一个rthmlQ可以把它看做页面引擎,然后用一个配|文件指定了面所应具有的模块和数据? 面模块p一个个装有数据的盒子,通过“页面引?+ 配置文g”把q些盒子l合hQ象搭积木一栗页面引擎是各用户共用的Q配|文件是各用L有的Q这样一装配hQ就形成了用L个性化面?br />
剩下的重点就是怎么定义配置文g。首先是要划清配|文件的责Q界线----它只负责定义盒子里的数据Q还有盒子的嵌套关系Q而大和位置{布局斚w则全部交lCSS去负责?br />
上面是初步想法,下面看看具体实现Q代码仅供参?br />
以下是某个用L配置文gQ我没用XMLQ而是用YAMLQ。board_1是指ID=1q个栏目所用的配置定义。topContent是一?div><div>的id|我把每个栏目的页面分?span>topContent、sideContent边(左或右由CSS军_Q?/span>primaryContent 主要、bottomContent底。topic是指d一个模块(盒子Q,昄一个主题内宏V和topiccM是还有显C图像的image、显CZ题列 表的topics、显C分cd表的categories{等{等。它们各有不同的属性|比如topic模块Q它需要定指它的主题idQ以及它所用的 view(topics/_show_hot.rhtml  or  topics/_show.rhtml{等)?br />
Q虽然这个配|文件抽象得q不够,但这样子已经可以解决我的需要了Q那
?/span>暂时q样先了。)

template.yml
 
  1. board_2:  
  2.   
  3. board_1:  
  4. - topContent:  
  5.   - topic:  
  6.       topic_id: 7  
  7.       view: topics/show_hot  
  8. - sideContent:  
  9.   - image:  
  10.       url: /images/news.jpg  
  11.   - categories:  
  12.       board: 5  
  13.       view: tree  
  14.   - topics:  
  15.       board: 5  
  16.       per_page: 4  
  17.       view: index_simple  
  18.   - topics:  
  19.       board: 6  
  20. - primaryContent:  
  21.   - topics:  
  22.       board: 4  
  23.       view: index  
  24.   - topic:  
  25.       topic_id: 7  
  26.       view: util/box  
  27.   
  28. board_3:  

然后在controller里把配置文gdQ再转化成模型类。我把各个界面模块看做一个个盒子Box
q是它的Box
ruby 代码
 
  1. class Box  
  2.   attr_accessor :html_id:view:boxes  
  3.   def initialize
  4.     @boxes=[]  
  5.   end  
  6. end  

q是topic模块?br />
ruby 代码
 
  1. class TopicBox < Box  
  2.   attr_accessor :topic_id  
  3. end  

q是Image模块?br />
ruby 代码
 
  1. class ImageBox < Box  
  2.   attr_accessor :url  
  3. end    

.....{?{, 其他的Box子类大同异

然后在一个controller里把q些配置信息转成Box模型c?br />
ruby 代码
 
  1. templates =  YAML::load(File.read("public/uploads/#{user_id}/config/template.yml"))
  2. template = templates.find{|o| o[0]=="board_#{@board.id}" }  
  3. args = template[1]  
  4.   
  5. @boxes = []  
  6. args.each do |arg1_hash|  
  7.   arg1_hash.each do |key1, value1|  
  8.     board_box = BoardBox.new  
  9.     board_box.html_id = key1  
  10.     @boxes << board_box  
  11.     value1.each do |arg2_hash|  
  12.       arg2_hash.each do |key2, value2|  
  13.         case key2  
  14.         when 'topics'  
  15.           box = TopicsBox.new  
  16.           box.board_id = value2['board']  
  17.           box.per_page = value2['per_page']||2  
  18.           box.view = value2['view']||'index_simple'  
  19.           board_box.boxes << box   
  20.         when 'categories'  
  21.           box = CategoriesBox.new  
  22.           box.board_id = value2['board']  
  23.           box.view = value2['view']||'list'  
  24.           board_box.boxes << box   
  25.         when 'image'  
  26.           box = ImageBox.new  
  27.           box.url = value2['url']  
  28.           board_box.boxes << box   
  29.         when 'topic'  
  30.           box = TopicBox.new  
  31.           box.topic_id = value2['topic_id']  
  32.           box.view = value2['view']||'util/box'  
  33.           board_box.boxes << box   
  34.         end  
  35.       end  
  36.     end  
  37.   end  
  38. end 

最后是它页面引擎(逻辑代码和页面代码؜在一P比较丑陋Q?
ruby 代码
 
  1. <% @boxes.each do |box1| %>  
  2. "<%=box1.html_id%>">  /span>
  3.   <% box1.boxes.each do |box2|  
  4.        p1 box2.class.to_s  
  5.   
  6.       case box2.class.to_s  
  7.       when 'TopicsBox'  
  8.         board_id = box2.board_id  
  9.         if board_id  
  10.           board = Board.find(board_id)  
  11.           topics = Topic.by_board_id(board_id, :per_page => box2.per_page)   
  12.           %>  
  13.           <%= render(:partial => "topics/#{box2.view}":locals => {:title =>board.title, :topics => topics })%>  
  14.         <%end  
  15.       when 'CategoriesBox'  
  16.         board_id = box2.board_id  
  17.         if board_id  
  18.           board = Board.find(board_id)  
  19.           categories = board.categories  
  20.           %>  
  21.           <%= render :partial => "categories/#{box2.view}":locals => {:board =>board, :categories => categories } %>  
  22.         <%end%>  
  23.       <%when 'ImageBox'%>  
  24.         <%= box_tag :header=>false%>  
  25.           <%=image_tag(box2.url, :border => 0) %>  
  26.         <%= end_box_tag %>  
  27.       <%when 'TopicBox'  
  28.         topic = Topic.find(box2.topic_id) %>  
  29.         <%=render(:partial => "#{box2.view}":locals => {:title =>topic.title, :content => topic.content, :topic => topic })%>  
  30.       <%end  
  31.   end%> 
 

q样Q以后想在页面上增加删除什么模块,修改配置文gp了。当然给用户用,q必d用AJAX来写个GUI界面QM能让用户手工L配置文g吧?br />

陈刚 2007-10-11 00:00 发表评论
]]>
抽取FCKEditor的浏览图片功?/title><link>http://www.aygfsteel.com/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.aygfsteel.com/chengang/archive/2007/09/26/148412.html</guid><wfw:comment>http://www.aygfsteel.com/chengang/comments/148412.html</wfw:comment><comments>http://www.aygfsteel.com/chengang/archive/2007/09/26/148412.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/chengang/comments/commentRss/148412.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/chengang/services/trackbacks/148412.html</trackback:ping><description><![CDATA[q去Q我们上传图片,一般都是一个文本框加一个“浏览”按钮,通过览按钮选取本地的图片,然后在提交表单后的逻辑中将囄上传x务器。现在,我们已经把FCKEditor应用在了我们的系l里Q而FCKEditor中带了有了图片上传和览功能。所以我想让这个“浏览”按钮不是从本地选取囄Q而是从FCKEditor传到服务器上的图片中来选D。也是把FCKEditor的“浏览”按钮,抽取出来?br /><div align="center">?陈刚 <a title="http://www.aygfsteel.com/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的文件浏览窗关闭后,会调用此函数Qƈ把所选图片的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: 览cdQ值可为Image/Flash/File/MediaQ如果ؓI字Ԍ则表C浏览所有类型的文g</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);">&</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);">&</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 /><</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);">><br /><</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<%= params[:user_id]%>', '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);">></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.aygfsteel.com/chengang/aggbug/148412.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/chengang/" target="_blank">陈刚</a> 2007-09-26 18:49 <a href="http://www.aygfsteel.com/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.aygfsteel.com/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.aygfsteel.com/chengang/archive/2007/09/26/148114.html</guid><wfw:comment>http://www.aygfsteel.com/chengang/comments/148114.html</wfw:comment><comments>http://www.aygfsteel.com/chengang/archive/2007/09/26/148114.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.aygfsteel.com/chengang/comments/commentRss/148114.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/chengang/services/trackbacks/148114.html</trackback:ping><description><![CDATA[一个多用户的系l,上传囑փ文g{,希望不同用户的图像上传到它专有的目录里。我最初查到在PHP版的FCKEditor是通过讄$Config('UserFilesPath')来实玎ͼ但Rails版的FCKEditor没有此项讄Q搜索UserFilesPath关键字后做出此判断)。接着Q我查看了FCKEditor关键的fckeditor_controller.rb的源代码Q似乎它q不支持此项讄。再看javaeye是怎么用FCKEditor的,发现它放弃了FCKEditor的上传功能。google了半天,除了那些转来转去的相同内容的帖子之外Q搞不懂有了google之后Q怎么q会有h费劲去{帖别人的文章Q,一点营M没有。在JavaEye发了个求助帖Q没人理 :-( ?传说中高手云集的JavaEyeQ其Rails版块真是hQ给人阴飕飕的感觉。没办法Q自己改源代码吧?br /><div align="center">?陈刚 <a title="http://www.aygfsteel.com/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.rbQ把它那几个privateҎ(gu)修改如下Q?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 在创建用hQ就建立好目录。这时可以去掉这部䆾代码Q提高运行效率?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 />另外Q它前面的常量UPLOADED_ROOT也没用了Q可以删掉?br /><br /><br />2. 在上面的代码?span style="color: rgb(0, 0, 0);">params[:uploaded]是关键,它就是我们动态定义的上传目录。该值来自于FCKEditor的一些html面Q它是通过get参数传入的。修改browser.html文gQ如下粗体部份)Q在它的urlh中把我们定义目录加入到get参数列中Q这样它?yu)可以传?/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);">></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);">&</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);">></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);">&</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.jsQ如下粗体部份)Q把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>&</b>Type=Image&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>&</b>Type=Flash&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>&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>&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);">微Y雅黑;宋体;黑体;隶书;楷体_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中加入一句(如下_体所C)?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']的D传到fckcustom.js的FCKConfig.uploaded里,q需要修改fckeditorcode_gecko.js和fckeditorcode_ie.jsQ这两个文g对javascriptq行了压~处理,修改h较难操作Q。我是参考了oFCKeditor.Config['CustomConfigurationsPath'] q个参数的蝲入实玎ͼ才找到这U鸟不生蛋的地方。搜索这两个文g的关键字<span style="color: rgb(0, 0, 0);">CustomConfigurationsPath</span>Q找到如下一行,然后加入一个else if判断(如下_体所C)?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了。如下粗体所C,把标准的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);"><%=</span><span style="color: rgb(0, 0, 0);">fckeditor_textarea(:topic, :content, :ajax </span><span style="color: rgb(0, 0, 0);">=></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);">=></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);">=></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);">=></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);">%></span></div><br /><br />修改完后需要重启WEB服务Q最后别忘记把public/javascripts/fckeditor和vendor/plugins/fckeditor/public/javascripts同步一下,原因见http://www.aygfsteel.com/chengang/archive/2007/09/24/147867.html<span style="color: rgb(0, 0, 0);"><b><br /></b></span><img src ="http://www.aygfsteel.com/chengang/aggbug/148114.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/chengang/" target="_blank">陈刚</a> 2007-09-26 10:13 <a href="http://www.aygfsteel.com/chengang/archive/2007/09/26/148114.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>定制FCKEditorQ以及其中文化http://www.aygfsteel.com/chengang/archive/2007/09/24/147867.html陈刚陈刚Mon, 24 Sep 2007 10:24:00 GMThttp://www.aygfsteel.com/chengang/archive/2007/09/24/147867.htmlhttp://www.aygfsteel.com/chengang/comments/147867.htmlhttp://www.aygfsteel.com/chengang/archive/2007/09/24/147867.html#Feedback0http://www.aygfsteel.com/chengang/comments/commentRss/147867.htmlhttp://www.aygfsteel.com/chengang/services/trackbacks/147867.html
?陈刚  www.chengang.com.cn
首先Q我们来看看FCKEditor在Rails中的q行Ҏ(gu),其插件主要是安装在vendor/plugins/fckeditor。主要的代码在vendor/plugins/fckeditor/public/javascriptsQ其中fckcustom.js是配|文Ӟ另外更深一层的子目录fckeditor中还有一个fckconfig.js也是配置文g。fckcustom.js配置的优先顺序大于fckconfig.jsQ因此一般修改fckcustom.js可以了Q不必去动fckconfig.js?br />
在启动WEBrick( ruby script/server)Ӟ会自动把vendor/plugins/fckeditor/public/javascripts的内容复制到public/javascripts目录。因此如果你修改了FCKEditor的配|文件之后,需要把复制到public/javascripts目录的FCKEditor相关文g删除掉,然后再重启WEBrick。当Ӟ你也可以直接修改public/javascripts目录的FCKEditor的缓存的配置文gQ这样不必重启WEBrickQ就可以立即看到修改效果。不q徏议你在完成修改后Q同时也要更新vendor/plugins/fckeditor/public/javascripts下的配置文gQ毕竟public/javascripts里的应该是临时文g?br />

1.中文?br />
在fckcustom.js里加入两(_体昄Q?br />
FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/silver/';
FCKConfig
.AutoDetectLanguage = false ;
FCKConfig
.DefaultLanguage = 'zh-cn'
 ;

2. 定制FCKEditor的工h
修改fckcustom.js里的如下目Q增删改自便?br />
FCKConfig.ToolbarSets["Simple"= [   。。?。。?br />

q里要注意一点,有些|上文章?span style="color: rgb(0, 0, 0);">:toolbarSet写成?/span>:toolbarKitQ这是错误的。如果你发现对工h的配|不起作用,那么要检查一下。正的写法如下Q?br />
<%=fckeditor_textarea(:topic, :content, :ajax => true, :toolbarSet => 'Simple', :width => '100%', :height => '300px'%>








陈刚 2007-09-24 18:24 发表评论
]]>
error_messages_for的中文化http://www.aygfsteel.com/chengang/archive/2007/09/19/146548.html陈刚陈刚Wed, 19 Sep 2007 09:35:00 GMThttp://www.aygfsteel.com/chengang/archive/2007/09/19/146548.htmlhttp://www.aygfsteel.com/chengang/comments/146548.htmlhttp://www.aygfsteel.com/chengang/archive/2007/09/19/146548.html#Feedback0http://www.aygfsteel.com/chengang/comments/commentRss/146548.htmlhttp://www.aygfsteel.com/chengang/services/trackbacks/146548.htmlApplicationHelper
?陈刚  www.chengang.com.cn  转蝲请声明出?/span>

  def error_messages_for(*params)
    
#add by glchengang
    key_hash = {}
    
if params.first.is_a?(Hash)
      key_hash 
=  params.first
      params
.delete_at(0)
    end
    
#add end

    options 
= params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
    objects 
= params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
    count   
= objects.inject(0) {|sum, object| sum + object.errors.count }
    
unless count.zero?
      html 
= {}
      [
:id, :class].each do |key|
        
if options.include?(key)
          value 
= options[key]
          html[key] 
= value unless value.blank?
        
else
          html[key] 
= 'errorExplanation'
        end
      end
      
# change by glchengang
      header_message = "?{count}个错?/span>"
#       header_message = "#{pluralize(count, 'error')} prohibited this #{(options[:object_name] || params.first).to_s.gsub('_', ' ')} from being saved"
      
      #add by glchengang

      error_messages = objects.map do |object|
        temp 
= []
        object
.errors.each do |attr, msg|
          temp 
<< content_tag(:li, (key_hash[attr] || attr) + msg) 
        end
        temp
      end
      
#add end

#        error_messages = objects.map {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } }

      content_tag(:div,
        content_tag(options[
:header_tag] || :h2, header_message) <<
#           content_tag(:p, 'There were problems with the following fields:') <<
          content_tag(:ul, error_messages),
        html
      )
    
else
      
''
    end
  end


使用依然兼容老的方式Q你也可以传入一个哈希表Q把模型字段昄成对应的中文Q示例如下:
<%= 
= {'username'=>'用户?/span>', 'password'=>'密码'}
error_messages_for h
, :user
%>

另外Q还要在environment.rb的最后插入以下代码:

errors = ActiveRecord::Errors.default_error_messages
errors[
:taken] = '已经被?/span>'
errors[
:blank] = '不能为空'



陈刚 2007-09-19 17:35 发表评论
]]>
让will_paginate的分|持ajaxhttp://www.aygfsteel.com/chengang/archive/2007/09/02/142077.html陈刚陈刚Sun, 02 Sep 2007 07:42:00 GMThttp://www.aygfsteel.com/chengang/archive/2007/09/02/142077.htmlhttp://www.aygfsteel.com/chengang/comments/142077.htmlhttp://www.aygfsteel.com/chengang/archive/2007/09/02/142077.html#Feedback14http://www.aygfsteel.com/chengang/comments/commentRss/142077.htmlhttp://www.aygfsteel.com/chengang/services/trackbacks/142077.html
?陈刚 (www.chengang.com.cn)
但一直搜不到它支持ajax分面的方?Q于是我参考它分页Ҏ(gu)的源代码(位于:vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb)Q稍微改写,变成了一个支持ajax的分|法。以下代码复制到application_helper里即可?br />

  
#-----------------------------------------
  # will_paginate插g的ajax分页
  #-----------------------------------------
  @@pagination_options = { :class => 'pagination',
        
:prev_label   => '上一?/span>',
        
:next_label   => '下一?/span>',
        
:inner_window => 4, # links around the current page
        :outer_window => 1, # links around beginning and end
        :separator    => ' ', # single space is friendly to spiders and non-graphic browsers
        :param_name   => :page,
        
#add by chengang
        :update =>nil, #ajax所要更新的html元素的id
        :url_suffix => ''  #url的后~Q主要是Z补全REST所需要的url
        #add end
        }
  mattr_reader 
:pagination_options

  def will_paginate_remote(entries 
= @entries, options = {})
    total_pages 
= entries.page_count

    
if total_pages > 1
      options 
= options.symbolize_keys.reverse_merge(pagination_options)
      page
, param = entries.current_page, options.delete(:param_name)
      
      inner_window
, outer_window = options.delete(:inner_window).to_i, options.delete(:outer_window).to_i
      
#add by chengang
      update =  options.delete(:update)
      suffix 
=  options.delete(:url_suffix)
      url 
= request.env['PATH_INFO'
      url 
+= suffix if suffix
      
#add end

      
min = page - inner_window
      
max = page + inner_window
      
if max > total_pages then min -= max - total_pages
      elsif 
min < 1  then max += 1 - min
      
end
      
      
current   = min..max
      beginning 
= 1..(1 + outer_window)
      tail      
= (total_pages - outer_window)..total_pages
      visible   
= [beginning, current, tail].map(&:to_a).flatten.sort.uniq
      links
, prev = [], 0

      visible
.each do |n|
        
next if n < 1
        
break if n > total_pages

        unless n 
- prev > 1
          
prev = n
          
#change by chengang
          text = (n==page ? n : "[#{n}]")
          links 
<< page_link_remote_or_span((n != page ? n : nil), 'current', text, param, update, url)
        
else
          
prev = n - 1
          links 
<< ''
          redo
        
end
      
end
      
      
#change by chengang
      links.unshift page_link_remote_or_span(entries.previous_page, 'disabled', options.delete(:prev_label), param, update, url)
      links
.push    page_link_remote_or_span(entries.next_page,     'disabled', options.delete(:next_label), param, update, url)
      
#change end

      content_tag 
:div, links.join(options.delete(:separator)), options
    
end
  
end
  
protected

  def page_link_remote_or_span(page
, span_class, text, param, update, url)
    unless page
      content_tag 
:span, text, :class => span_class
    
else
      link_to_remote text
, :update => update, :url => "#{url}?#{param.to_sym}=#{page}", :method=>:get
    
end
  
end


在view中的使用如下所C?
          <%=will_paginate_remote @topics, :update => 'topicList', :url_suffix => url_suffix%>




陈刚 2007-09-02 15:42 发表评论
]]>
在Rails中用FCKeditor插g实现WEB富文本编?/title><link>http://www.aygfsteel.com/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.aygfsteel.com/chengang/archive/2007/08/25/139287.html</guid><wfw:comment>http://www.aygfsteel.com/chengang/comments/139287.html</wfw:comment><comments>http://www.aygfsteel.com/chengang/archive/2007/08/25/139287.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/chengang/comments/commentRss/139287.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/chengang/services/trackbacks/139287.html</trackback:ping><description><![CDATA[比如象BlogJavaq里~辑器就应该是用的FCKeditor QFCKeditor 相当有名Q它有PHP、JSP、rails{多个版本,核心都是一些javascript代码?br /><br /><div style="text-align: center;">?陈刚  (www.chengang.com.cn)<br /></div><br />环境Qubuntu linux 7.0.4  +  ruby 1.8.5 + Rails 1.2.3 + FCKeditor 0.4.1 <br /><br />直接从它的subversion库里取得该Rails插g。先q入C的项目根目录Q再执行如下命o<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 />其他说明Q?br />(1)你的linux必须先安装了subversion。(ubuntu里用新立得搜subversion卛_Q?br />(2)把命令中的install 改ؓ destoryQ可以删除安装?br />(3)我取到的?007q?月䆾最后更新的, v 0.4.1?br />(4)FCKeditor安装在项目根目录下的vendor/plugins/fckeditor 里,<br />(5)vendor/plugins/fckeditor里的README很值得一读,我碰到Ajax问题Q查了所以网上的中文资料都没有提刎ͼ在这个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);"><%=</span><span style="color: rgb(0, 0, 0);"> javascript_include_tag :fckeditor </span><span style="color: rgb(0, 0, 0);">%></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);"><%=</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);">%></span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><br />在需要富文本的Form表单用如下语句生成一个富文g~辑框:<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);"> 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);">=></span><span style="color: rgb(0, 0, 0);"> 'Simple', :width </span><span style="color: rgb(0, 0, 0);">=></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);">=></span><span style="color: rgb(0, 0, 0);"> '200px') </span><span style="color: rgb(0, 0, 0);">%></span></div><br />说明Qtopic对应模型对象,content对应它的字段。也是要求当前要有@topicq个实例变量?br /><br /><br />如果是用了ajaxQ则需要在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);"><%=</span><span style="color: rgb(0, 0, 0);"> form_remote_tag(:update </span><span style="color: rgb(0, 0, 0);">=></span><span style="color: rgb(0, 0, 0);"> update,<br />                     <span style="color: red;"> :before </span></span><span style="color: red;">=></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);">=></span><span style="color: rgb(0, 0, 0);"> {:controller </span><span style="color: rgb(0, 0, 0);">=></span><span style="color: rgb(0, 0, 0);"> 'topics', :action </span><span style="color: rgb(0, 0, 0);">=></span><span style="color: rgb(0, 0, 0);"> 'create', :template </span><span style="color: rgb(0, 0, 0);">=></span><span style="color: rgb(0, 0, 0);"> 'show'} )</span><span style="color: rgb(0, 0, 0);">%></span><span style="color: rgb(0, 0, 0);"><br /></span></div><br />q且富文件编辑框要加一个ajax=true的选项Q?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);"> fckeditor_textarea(:topic, :content, <span style="color: red;">:ajax </span></span><span style="color: red;">=> true</span><span style="color: rgb(0, 0, 0);"><span style="color: red;">, </span>:toolbarKit </span><span style="color: rgb(0, 0, 0);">=></span><span style="color: rgb(0, 0, 0);"> 'Simple', :width </span><span style="color: rgb(0, 0, 0);">=></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);">=></span><span style="color: rgb(0, 0, 0);"> '600px') </span><span style="color: rgb(0, 0, 0);">%></span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><br /><br /><br /><br />在上传囄的功能时到了错误。弹出出alert对话框,昄QError on file upload.Error number: 403 <br /><p>在日志里昄如下Q表面上看好象是路由配置的问?/p><p>ActionController::RoutingError (no route found to match "/fckblank.html" with {:method=>: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扑ֈ了答案,q是一个BUG <p>解决Ҏ(gu) Q?br /></p><p>修改Qvendor/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.aygfsteel.com/chengang/aggbug/139287.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/chengang/" target="_blank">陈刚</a> 2007-08-25 16:44 <a href="http://www.aygfsteel.com/chengang/archive/2007/08/25/139287.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̷</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">կ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">֣</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̶</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">崲</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ޭ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽԶ</a>| <a href="http://" target="_blank">Ƹ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ѱ</a>| <a href="http://" target="_blank">Ϸ</a>| <a href="http://" target="_blank">»</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ﴨ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">᰸</a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>