English 中文(简体)
Deploying Sinatra app on Dreamhost/Passenger with custom gems
原标题:

I ve got a Sinatra app that I m trying to run on Dreamhost that makes use of pony to send email. In order to get the application up and running at the very beginning (before adding pony), I had to gem unpack rack and gem unpack sinatra into the vendor/ directory, so this was my config.ru:

require  vendor/rack/lib/rack 
require  vendor/sinatra/lib/sinatra 

set :run, false
set :environment, :production
set :views, "views"

require  public/myapp.rb 
run Sinatra::Application

I have already done gem install pony and gem unpack pony (into vendor/). Afterwards, I tried adding require vendor/sinatra/lib/pony to config.ru only to have Passenger complain about pony s dependencies (mime-types, tmail) not being found either!

There has to be a better way to use other gems and tone down those long, ugly, redundant requires. Any thoughts?

最佳回答

I d recommend creating your own gem path "somewhere" then adding it in your config.ru like:

ENV[ GEM_PATH ] = xxx
Gem.clear_paths

then install your gems into that

问题回答

Install Ruby gems on dreamhost

https://c.kat.pe/installing-ruby-gems-on-dreamhost

Change config.ru (works for Sinatra 1.0)

require rubygems

require vendor/sinatra/lib/sinatra.rb

ENV[ GEM_HOME ] =  /home/username/.gems 
ENV[ GEM_PATH ] =  $GEM_HOME:/usr/lib/ruby/gems/1.8 
require  rubygems 
Gem.clear_paths

disable :run, :reload

set :environment, :production

require  yourapp 
run Sinatra::Application

Hope it helps someone.

I am using pony and a lot of other gems for my Sinatra. It should work well for you too. It s just those two lines (GEM_HOME and GEM_PATH) you have to add on your config.

It took me ages to find that you can simply use "gem install sinatra" and gem will figure out (because the system directories are read-only) that you will need to use a local gem install directory. As of now, there seems to be no need to set any special environment at all. It figures out to use $HOME/.gem as the local gem path and everything just works. No need for require vendor/stuff at all. I did find I had to add $HOME/.gem/ruby/1.8/bin to my path in order to execute binaries installed by gems.

Here s my config.ru (for Dreamhost)

## Passenger should set RACK_ENV for Sinatra
require  test 
set :environment, :development
run Sinatra::Application

Later edit: This is all well and fine, but there remains the issue that Passenger can t find my gems when the job initially starts up.

My config.ru is just simple as:

require  rubygems 
require  vendor/sinatra/lib/sinatra.rb 
require  app.rb 

and app.rb head:

require  yaml 
require  haml 
require  ostruct 
require  date 
require  pp 

module FlytoFB
    log = File.new("sinatra.log", "a")
    STDOUT.reopen(log)
    STDERR.reopen(log)

    configure do

            enable :logging, :dump_errors
            set :app_file, __FILE__
            set :reload, true
            set :root, File.dirname(__FILE__)
            set :environment, :production
            set :env, :production
            set :run, false

            set :raise_errors, true
      set :public,  public 

            error do
                    e = request.env[ sinatra.error ]
                    puts e.to_s
                    puts e.backtrace.join("
")
                    "Application Error!"
            end

            not_found do
              "Page not found!"
      end




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签