OCRA and Rails 3

600 views
Skip to first unread message

Henri Karhatsu

unread,
Jan 23, 2011, 7:01:54 AM1/23/11
to OCRA One-Click Application Builder
I'm trying to create exe file with OCRA for Rails 3. The OCRA GitHub
page suggests using this kind of command:

ocra someapp/script/server someapp --no-dep-run --add-all-core --
gemfile someapp/Gemfile

However, in Rails 3 there is no file script/server, just the command
"rails server". So I have replaced this with:

ocra someapp/script/rails someapp --no-dep-run --add-all-core --
gemfile someapp/Gemfile

...and run the exe file as:
rails.exe server

This gives me an error:
C:/Users/Henri/AppData/Local/Temp/ocrE51B.tmp/lib/ruby/gems/1.8/gems/
rack-1.2.1/lib/rack/server.rb:267:in `initialize': No such file or
directory - C:/Users/Henri/tmp/pids/server.pid (Errno::ENOENT)

I guess the correct path should be C:/Users/Henri/someapp/tmp/pids/
server.pid. Any ideas how to solve this problem?

Henri Karhatsu

unread,
Feb 1, 2011, 1:38:23 AM2/1/11
to OCRA One-Click Application Builder
If someone is interested, I got Rails 3 working but I had to use
tar2rubyscript together with OCRA:

Preparements (part of the instructions borrowed from
http://www.erikveen.dds.nl/tar2rubyscript/):

- someapp/init.rb:
at_exit do
require "irb"
require "drb/acl"
end

unless defined?(Ocra)
load "script/exe_server.rb"
end

- someapp/script/exe_server.rb (modified based on script/rails):
ENV["RAILS_ENV"] = "production" # I want that the exe runs
automatically in the production mode
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)

# copied from: railties/lib/rails/commands.rb:
require 'rails/commands/server'
Rails::Server.new.tap { |server|
require APP_PATH
Dir.chdir(Rails.application.root)
server.start
}

- someapp/config/database.yml (you could this dynamically as well in
application.rb):
production:
adapter: sqlite3
database: <%= File.expand_path('../production.sqlite3',
ENV["OCRA_EXECUTABLE"]) %>

Building (in the parent folder of someapp):

1. tar2rubyscript someapp (use https://github.com/ryanbooker/tar2rubyscript,
not gem install tar2rubyscript)
2. ocra someapp.rb --add-all-core --gemfile someapp\Gemfile --dll
sqlite3.dll

This gives me someapp.exe which I'm able to run in a computer without
Ruby. You just need to have production.sqlite3 file in the same folder
with the exe file.

Of course it would be nice to do the same without tar2rubyscript by
just using OCRA but I guess this is fine too.

David Simon

unread,
Feb 1, 2011, 8:32:53 AM2/1/11
to ruby...@googlegroups.com
I will look into the Ocra problem you mentioned; Rails compatibility
is pretty much my priority. Hopefully I can get it working without
tar2rubyscript.

David Simon

unread,
Feb 3, 2011, 1:22:59 PM2/3/11
to ruby...@googlegroups.com
Ok, this appears to be a rails bug; it cannot deal with script\rails being called from anywhere but the root of the rails project directory. You can replicate the error message you got by doing:

$ rails new testproject
$ cd testproject/app # Or any directory under testproject
$ ruby ../script/rails server

I consider this to be a problem in Rails, but I these sorts of issues with working directories are common enough that Ocra users would probably benefit from an easy workaround. Maybe if Ocra had an option to switch to the application directory before starting? Lars, what do you think?

In the meantime, you can fix this issue by writing an intermediate script that changes the directory before starting the server. Just place this in a file in the root of your rails project named "start.rb":

Dir.chdir(File.dirname(__FILE__))
load 'script/rails'

Then, you can create a working exe with something like the following command:
ocra testproject\start.rb testproject --no-dep-run --add-all-core --gemfile testproject\Gemfile --output testproject.exe -- server

This has another couple of advantages over the command you pasted:
1. The created EXE file is named specifically after the project, not just a generic name like "rails.exe"
2. The server argument is automatically passed through to rails, no need to provide it yourself on the command line or in a shortcut

Henri Karhatsu

unread,
Feb 16, 2011, 1:43:21 PM2/16/11
to OCRA One-Click Application Builder
I finally got time to try this and got it working. Thanks David!

Onno van der Straaten

unread,
Jul 3, 2012, 10:16:52 AM7/3/12
to ruby...@googlegroups.com
This will build the exe without problems but fail when the exe is started. Bundler cannot be found, so this won't run succesfully. Is there a way to include bundler as well?

Onno van der Straaten

unread,
Jul 3, 2012, 10:23:53 AM7/3/12
to ruby...@googlegroups.com
Why can't it load bundler, my app is working fine!?

:/Users/ostraa~1/AppData/Local/Temp/ocrDBE6.tmp/lib/ruby/1.9.1/rubygems/custom_equire.rb:36:in `require': cannot load such file -- bundler (LoadError)
       from D:/Users/OSTRAA~1/AppData/Local/Temp/ocrDBE6.tmp/lib/ruby/1.9.1/rubgems/custom_require.rb:36:in `require'


Henri Karhatsu

unread,
Jul 6, 2012, 7:35:55 AM7/6/12
to ruby...@googlegroups.com
Onno, check these out:

https://github.com/larsch/ocra/pull/41
https://github.com/larsch/ocra/issues/38

Maybe you have the same problem as I had.
Reply all
Reply to author
Forward
0 new messages