<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d4684235500622716427\x26blogName\x3dCaiwangqin\x27s+blog\x26publishMode\x3dPUBLISH_MODE_HOSTED\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://blog.caiwangqin.com/search\x26blogLocale\x3dzh_CN\x26v\x3d2\x26homepageUrl\x3dhttp://blog.caiwangqin.com/\x26vt\x3d3393395200455623441', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe", messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER, messageHandlers: { 'blogger-ping': function() {} } }); } }); </script>

Caiwangqin's blog

Focus on Life, Cloud Service, Smart Hardware, Architecture, Technic and beyond…

Rails Application 引用外部路径的文件

2006年10月24日星期二

曹维远发Email给我提到这问题,可能其他人也会碰到这个问题,因此将我的回复发布在Blog中。


Caiwangqin, 你好,


我是曹维远,网名cvu,在uuzone上我们曾经互相加过好友。

初次交流,本来想说些仰慕的话,大家都忙,略过。

写信给你的直接目的是问一个rails的问题,我想让browser可以访问到我的一个硬盘目录里的图片,而这个目录不在public下面。

IIS管这个叫Virtual Directory, Apache叫Alias.

我查了rails的各类文档,routes.rb是最接近的,但是好像解决不了我的问题。

又有apache+mongrel的方案,我按照mongrel网站上的介绍,和冰狗的翻译,配置了httpd.conf如下


<VirtualHost *>
    ServerName typo
    ProxyPass / http://localhost:3002/
    ProxyPassReverse / http://localhost:3002
    ProxyPass /images !
    ProxyPass /stylesheets !
    ProxyPass /icons !
    #continue with other static files that should be served by apache

    Alias /images ${path}/rails_apps/typo-2.6.0/public/images
    Alias /stylesheets ${path}/rails_apps/typo-2.6.0/public/stylesheets
    Alias /icons ${path}/apache/icons
    #continue with aliases for static content

</VirtualHost>



但还是不行,不知道你有没有这方面经验。

谢谢!



我也曾想过同样的问题,好像通过Rails的routes.rb是不可以引用外部路径的,routes.rb是Rails内部的Rewrite规则。但可以通过将RoR应用配置成一个别名,然后将外部路径配置成另外的别名,即可在Rails Application中使用”/images/example.jpg”的方式引用外部路径了。提供参考(以下用Lighttpd示范,Apache配制类似):


server.document-root = “C:/lighttpd/htdocs/”

alias.url = (

“/images/” => “${path}/rails_apps/typo-2.6.0/public/images”,

“/stylesheets/” => “${path}/rails_apps/typo-2.6.0/public/stylesheets”,

“/icons/” => “${path}/apache/icons”

)

$HTTP[”url”] =~ “^/typo/” {

server.document-root = “e:/work/ror/typo/public”
server.error-handler-404 = “/dispatch.scgi”
server.indexfiles = ( “dispatch.fcgi” )
scgi.debug=0
scgi.server = ( “dispatch.scgi” => ((
“host” => “127.0.0.1″,
“port” => 9999,
“check-local” => “disable”,
“disable-time”=>0
)) )
}



希望能够有所帮助。


标签:

posted by Caiwangqin, 03:49

0 Comments:

发表评论

订阅 博文评论 [Atom]

<< 主页