Skip to content

Ramblings

Musings of Matt Williams
  • Blog
  • About
  • Chibi
  • Ruby Blender
  • Archives
  • Log in
 
Less
More
Trim
Untrim
« Older
Home
Loading
Newer »
Archive for the 'rails' Category
02Mar10 Rails & JRuby in a Jar
gotchas jruby rails tips
4 Comments

For political reasons, I needed to ship a single jar file.  I didn’t want to have the overhead of a war & an appserver, so I set out to embed my rails app within a single jar file.  I needed to make some changes in order to get it to work.

This assumes Rails 2.3.5 and JRuby 1.4.0.

First, you need to create your rails app.   Freeze rails and any gems required.

Next download jruby-complete.  Once you’ve done so, unzip it.  I’m assuming you’ve unzipped it to complete.

Note: When you repackage the jar file, DO NOT use jar.  Use zip.  This is very important.  If you don’t, you’ll trash your jruby instance.

Copy your rails instance to complete/META-INF/jruby.home. I assume it will be complete/META-INF/jruby.home/rails.

Next create complete/META-INF/jruby.home/bin/server with the following content:


#!/usr/bin/env ruby

RAILS_ROOT = File.join(File.dirname(File.dirname(__FILE__)),'rails')

require File.join(RAILS_ROOT,'config/boot')
require 'commands/server'

The RAILS_ROOT needs to be set in order to have the proper paths within the jar file.

Next, edit complete/META-INF/jruby.home/rails/vendor/rails/railties/lib/initializer.rb In the set_root_path method, edit it so it looks like this:


    def set_root_path!
      raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT)
      raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT)
      # I changed this... mkw21 20100301
      @root_path = RAILS_ROOT
        # Pathname is incompatible with Windows, but Windows doesn't have
        # real symlinks so File.expand_path is safe.
#        if RUBY_PLATFORM =~ /(:?mswin|mingw)/
#          File.expand_path(::RAILS_ROOT)#

        # Otherwise use Pathname#realpath which respects symlinks.
#        else
#          Pathname.new(::RAILS_ROOT).realpath.to_s
#        end

      Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
      ::RAILS_ROOT.replace @root_path
    end

This is related to paths within the jar file.

Additionally, you need to change the initialize_logger method. (this might not be needed, see below). Change


          logger = ActiveSupport::BufferedLogger.new(configuration.log_path)

to


          logger = ActiveSupport::BufferedLogger.new("/tmp/transfer.log")

The idea is to change it to something definitely outside the jar. The reason I did this, and didn’t change the config in environment.rb was that the changes in environment.rb were not getting picked up. I’ve since come to the belief that this is due to an issue with the Rack LogTailer detailed at https://rails.lighthouseapp.com/projects/8994/tickets/2350-logtailer-ignores-configlog_path. So complete/META-INF/jruby.home/rails/vendor/rails/railties/lib/rails/rack/log_tailer.rb needs to be edited. Edit the EnvironmentLog assignment to match the file we’d specified. (You may be able to substitute RAILS_DEFAULT_LOGGER but I have not tested that)


      EnvironmentLog = "/tmp/transfer.log"

That’s pretty much it. Zip up your exploded jar from the complete directory: zip -r ../complete.zip *. Then you can run it via java -jar complete.jar -S server.

Enjoy!

05Sep08 Converting a rails app from 1.2.6 to 2.1
rails
0 Comments

This is the first in a series(???) of posts detailing things that I’ve found in the process of updating rails (and other plugins/gems) for an application.  Due to politics, it’s using JRuby, running inside a JBoss container, with a Derby backend.

Things which are getting updated include:

  • Rails
  • ActiveRecord-JDBC
  • ActiveScaffold
  • ActiveScaffoldExport
  • Goldspike is being replaced with Warbler

Here’s a list of what I’ve encountered thus far:

Continue reading ‘Converting a rails app from 1.2.6 to 2.1′

25Aug08 Rails Project Setup Script
rails
1 Comment

I got tired of typing the same commands all the time and/or looking up urls for plugins.  Hence this script….  Yes, I know it’s been done before, but this does what I want (for now; I’m sure I’ll edit it).

It does the following:

  • Creates rails instance (optionally setting the database, etc.)
  • Installs rspec & rspec-rails
  • Installs acts_as_statemachine
  • Installs restful_authentication
  • Modifies routes.rb
  • Adds an observer
  • Adds email settings

You can see the script below the cut or download it here:start-rails

(Edit: Removed an un-escaped pair of parens)

Continue reading ‘Rails Project Setup Script’

19Aug08 rspec, restful_authentication, and login_required
rails tips
6 Comments

This is partly for myself, and partly for anyone after me…..

I have a controller generated via rspec_scaffold — yes, I know, it might not be what all the cool kids are doing, but it works.  I also have restful_authentication set up to use rspec.  So, when I go to add before_filter :login_required, autotest frowns at me.  After much trial and error, and googling (with false hits and things that didn’t work), I finally achieved a smiley face with the following added to my controller’s spec:

  before :each do
   @current_user = mock_model(User, :id => 1)
   controller.stub!(:current_user).and_return(@current_user)
   controller.stub!(:login_required).and_return(:true)
  end
  fixtures :users
19Aug08 autotest reminder (or why did it go boom?)
gotchas rails ruby tips
0 Comments

autotest / zentest are really useful tools.  However, it’s important to remember to run migrations for the test database — otherwise your tests will fail (miserably!)

I’ve found the following to be helpful for using autotest:

  • Getting started with Autotest – Continuous Testing
  • Autotest RSpec Notifications for Ubuntu « My Pragmatig life
12Aug08 O_RLY? A Ruby/Rails implementation of snowl (Part I)
programming rails
0 Comments

Recently Mozilla Labs released a prototype of snowl, a rss/atom/twitter feed reader. It is a firefox plugin and provides two views of messages — a “traditional” message view, as well as a “river of news“. I thought that this could be easily “redone” as a rails application. The rest of this article steps through the process of creating it.
Continue reading ‘O_RLY? A Ruby/Rails implementation of snowl (Part I)’

 
Browse Archives »
  • administrivia (6)
  • books (1)
  • Computers (2)
  • css (3)
  • eating crow (1)
  • games (1)
  • glassfish (1)
  • gotchas (16)
  • howto (2)
  • idiocy (3)
  • javascript (4)
  • jboss (4)
  • jruby (6)
  • Just Enough Programming (7)
  • life hacking (2)
  • mini sagas (1)
  • miscellany (1)
  • monitoring (1)
  • mysql (1)
  • philosophy (4)
  • php (1)
  • programming (17)
  • rails (6)
  • rants (2)
  • refactoring (1)
  • ruby (14)
  • tips (9)
  • tools (2)
  • Uncategorized (9)
  • utilities (3)
  • web (5)
  • web design (3)
 

Latest

  • Rails & JRuby in a Jar
  • Fractal Terrain Generation
  • Quick thought on programming and distractions
  • Using jnp as a JBoss heartbeat
  • z-index and events
  • JBoss port confusion
  • SSL Joys
  • After long silence
  • New Ruby Blog
  • Javascript with CSS Sprites Animation

Flickr

layout_newm3headerTerrain Testa

Blogroll

  • Development Blog
  • Documentation
  • Plugins
  • Suggest Ideas
  • Support Forum
  • Themes
  • WordPress Planet

Search

Browse by Category

  • administrivia (6)
  • books (1)
  • Computers (2)
  • css (3)
  • eating crow (1)
  • games (1)
  • glassfish (1)
  • gotchas (16)
  • howto (2)
  • idiocy (3)
  • javascript (4)
  • jboss (4)
  • jruby (6)
  • Just Enough Programming (7)
  • life hacking (2)
  • mini sagas (1)
  • miscellany (1)
  • monitoring (1)
  • mysql (1)
  • philosophy (4)
  • php (1)
  • programming (17)
  • rails (6)
  • rants (2)
  • refactoring (1)
  • ruby (14)
  • tips (9)
  • tools (2)
  • Uncategorized (9)
  • utilities (3)
  • web (5)
  • web design (3)

Browse by Tag

  • 1.2.6
  • 2.1
  • administrivia
  • autotest
  • books
  • controller
  • css
  • feed-normalizer
  • feeds
  • gotchas
  • idiocy
  • irb
  • Java
  • javascript
  • jboss
  • jruby
  • just enough programming
  • mini sagas
  • open-uri
  • philosophy
  • php
  • pragmatism
  • programming
  • quotations
  • rails
  • rants
  • reading
  • restful_authentication
  • rspec
  • rss
  • ruby
  • rubygems
  • scriptaculous
  • setup
  • simplicity
  • sprites
  • statemachine
  • tips
  • treetop
  • utilities
  • web
  • web design
  • websense
  • yaml
  • zentest

Browse by Month

  • March 2010 (1)
  • September 2009 (1)
  • August 2009 (2)
  • July 2009 (2)
  • May 2009 (1)
  • April 2009 (1)
  • February 2009 (4)
  • January 2009 (2)
  • December 2008 (2)
  • November 2008 (5)
  • October 2008 (3)
  • September 2008 (12)
  • August 2008 (28)
 
 
  • Blog
  • About
  • Chibi
  • Ruby Blender
  • Archives
  • Log in
 


Theme Design by Jay Kwong | Powered by WordPress and K2

 

Home Top Archives Entries FeedComments Feed