2014-05-14 19 views
1

我想弄清楚如何正確設置rack-rewrite並且遇到了一些麻煩。我是一個小菜鳥,該網站並沒有超清晰的設置。如果有人對此有更多的瞭解,我有幾個問題。適用於本地dev和heroku的獨角獸機架重寫適當的配置

1)我是否需要將寶石放在我的gemfileconfig.ru文件中? (根據自述文件部分中的「Sample rackup file」)

2)我是否需要在我的config.ru文件和我的config/application.rb文件中都有機架重寫設置? (根據自述文件中的「示例rackup文件」和「Rails應用程序中的示例用法」部分)

3)在我的application.rb文件中,我將配置?在class Application < Rails::Application區塊?

4)我已經嘗試了上面的兩個,但是,當我開始unicorn本地,我收到以下錯誤

$ unicorn 
I, [2014-05-13T16:57:00.926144 #17432] INFO -- : Refreshing Gem list 
/config/environment.rb:2:in `require': /config/application.rb:98: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError) 
    from /config/environment.rb:2:in `<top (required)>' 
    from config.ru:4:in `require' 
    from config.ru:4:in `block in <main>' 
    from /Users/me/.rvm/gems/[email protected]/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval' 
    from /Users/me/.rvm/gems/[email protected]/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize' 
    from config.ru:1:in `new' 
    from config.ru:1:in `<main>' 
    from /Users/me/.rvm/gems/[email protected]/gems/unicorn-4.8.2/lib/unicorn.rb:48:in `eval' 
    from /Users/me/.rvm/gems/[email protected]/gems/unicorn-4.8.2/lib/unicorn.rb:48:in `block in builder' 
    from /Users/me/.rvm/gems/[email protected]/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:760:in `call' 
    from /Users/me/.rvm/gems/[email protected]/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:760:in `build_app!' 
    from /Users/me/.rvm/gems/[email protected]/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:137:in `start' 
    from /Users/me/.rvm/gems/[email protected]/gems/unicorn-4.8.2/bin/unicorn:126:in `<top (required)>' 
    from /Users/me/.rvm/gems/[email protected]/bin/unicorn:23:in `load' 
    from /Users/me/.rvm/gems/[email protected]/bin/unicorn:23:in `<main>' 
    from /Users/me/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `eval' 
    from /Users/me/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `<main>'>' 

--------------- -----更新--------------------

我已經解決了上述問題。看起來這個寶石非常多才多藝,你可以在application.rb,config.ru中設置它,或者在初始化程序目錄中創建一個rack_rewrite.rb文件。

有沒有人有任何意見,最好的地方是把代碼放在哪裏?

另外,有沒有一種方法來解決重定向中尾隨/?比如說,有沒有辦法將它壓縮成一行?

r301 '/for-gyms-and-rec-centers', '/venues/3' 
r301 '/for-gyms-and-rec-centers/', '/venues/3/ 

回答

0

如果您使用的是Rails應用程序,那麼你或許應該保持乾淨,只有把機架改寫創業板申報你的Gemfile,你不需要它在config.ru文件。最重要的是,你只需要你的application.rb文件中的配置代碼。

您可以安全地將塊放在班級塊的末尾,就在班級的最後一個end之前(恰好在模塊的最後一圈之前)。請記住,使用獨角獸時,請注意將堆棧中間件插入堆棧的位置 - 我相信您需要在Rack::Runtime之前定位目標,而不是Rack::Lock

至於最後的斜槓問題,我相信你可以有'/for-gyms-and-rec-centers(.*)',這應該趕上它。