<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Admoo Labs &#187; Web Development</title>
	<atom:link href="http://blog.admoolabs.com/category/webdev/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.admoolabs.com</link>
	<description>Bringing fun back to the web.</description>
	<lastBuildDate>Sun, 07 Mar 2010 13:45:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JRuby, WAR, and Paperclip</title>
		<link>http://blog.admoolabs.com/jruby-war-and-paperclip/</link>
		<comments>http://blog.admoolabs.com/jruby-war-and-paperclip/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 06:42:56 +0000</pubDate>
		<dc:creator>Christopher Rigor</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[paperclip]]></category>

		<guid isPermaLink="false">http://blog.admoolabs.com/?p=181</guid>
		<description><![CDATA[If you deploy a jruby on rails application as a war file, the file structure is different from a normal rails application.

&#124;-- 404.html
&#124;-- 422.html
&#124;-- 500.html
&#124;-- WEB-INF
&#124;   &#124;-- app
&#124;   &#124;-- config
&#124;   &#124;-- gems
&#124;   &#124;-- lib
&#124;   &#124;-- log
&#124;   &#124;-- tmp
&#124;   &#124;-- vendor
&#124;  [...]]]></description>
			<content:encoded><![CDATA[<p>If you deploy a jruby on rails application as a war file, the file structure is different from a normal rails application.</p>
<pre class="brush: bash; light: true;">
|-- 404.html
|-- 422.html
|-- 500.html
|-- WEB-INF
|   |-- app
|   |-- config
|   |-- gems
|   |-- lib
|   |-- log
|   |-- tmp
|   |-- vendor
|   `-- web.xml
|-- favicon.ico
|-- images
|   `-- rails.png
|-- index.html
|-- javascripts
|   `-- application.js
|-- robots.txt
|-- stylesheets
|-- system
</pre>
<p>The rails directories are under WEB-INF while the files and directories normally on public/ are on the root directory of the j2ee web app. In glassfish, the root of a rails app named &#8216;labs&#8217; is $GLASSFISH_HOME/domains/domain1/applications/j2ee-modules/labs.</p>
<p>Since the &#8216;public&#8217; directory is not under RAILS_ROOT, you shouldn&#8217;t be using RAILS_ROOT/public when saving files. Instead, use Rails.public_path. Paperclip saves files on &#8220;:rails_root/public/system/:attachment/:id/:style/:filename&#8221; by default. You can add the :path option to change this.</p>
<pre class="brush: ruby; light: true;">
has_attached_file :image, :styles =&gt; { :square =&gt; &quot;48x48#&quot; }, :path =&gt; &quot;#{Rails.public_path}/system/:attachment/:id/:style/:filename&quot;
</pre>
<p>The uploaded files should now be saved on the correct directory.</p>
<p>While this works, it&#8217;s probably not a good idea to save uploaded files on the j2ee-modules/ directory. When you undeploy the &#8216;labs&#8217; app on glassfish, it will remove the &#8216;labs&#8217; directory on j2ee-modules which includes all the uploaded files.</p>
<p>We can symlink labs/system to a directory outside of the glassfish directory. We can also use a different directory for paperclip which doesn&#8217;t use Rails.public_path or Rails.root. (I haven&#8217;t tested both.)</p>
<p>This is only an issue when deploying your jruby apps as a war file. If you&#8217;re using the glassfish gem, you don&#8217;t change the file structure at all. You just run jruby -S glassfish. If you&#8217;re using directory-based deployment on glassfish, undeploying the app doesn&#8217;t remove the directory. </p>
<p>Where are you saving the uploaded files? Let me know in the comments if you have other suggestions. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.admoolabs.com/jruby-war-and-paperclip/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Running Glassfish in Server Mode</title>
		<link>http://blog.admoolabs.com/glassfish-server-mode/</link>
		<comments>http://blog.admoolabs.com/glassfish-server-mode/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 13:59:57 +0000</pubDate>
		<dc:creator>Christopher Rigor</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[jruby]]></category>

		<guid isPermaLink="false">http://blog.admoolabs.com/?p=177</guid>
		<description><![CDATA[
jruby --server -S glassfish -e production -p 4400

Glassfish doesn&#8217;t accept an option to run in server mode, but jruby does, so instead of using glassfish -e production, use jruby -S glassfish and add &#8211;server.
]]></description>
			<content:encoded><![CDATA[<pre class="brush: bash; light: true;">
jruby --server -S glassfish -e production -p 4400
</pre>
<p>Glassfish doesn&#8217;t accept an option to run in server mode, but jruby does, so instead of using glassfish -e production, use jruby -S glassfish and add &#8211;server.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.admoolabs.com/glassfish-server-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JRuby and the Glassfish Gem</title>
		<link>http://blog.admoolabs.com/jruby-glassfish-ge/</link>
		<comments>http://blog.admoolabs.com/jruby-glassfish-ge/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 13:23:14 +0000</pubDate>
		<dc:creator>Christopher Rigor</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.admoolabs.com/?p=169</guid>
		<description><![CDATA[The glassfish gem is another way to run a rails application in jruby. Before glassfish, I was using jruby script/server.
Using glassfish is simple. Install the gem and run jruby -S glassfish. However, I got a &#8220;missing gem&#8221; error.

$ sudo jgem install glassfish
Successfully installed glassfish-1.0.2-universal-java
1 gem installed

$ jruby -S glassfish
Starting GlassFish server at: 0.0.0.0:3000 in development [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://glassfishgem.rubyforge.org/">glassfish gem</a> is another way to run a rails application in jruby. Before glassfish, I was using jruby script/server.</p>
<p>Using glassfish is simple. Install the gem and run jruby -S glassfish. However, I got a &#8220;missing gem&#8221; error.</p>
<pre class="brush: bash; light: true;">
$ sudo jgem install glassfish
Successfully installed glassfish-1.0.2-universal-java
1 gem installed

$ jruby -S glassfish
Starting GlassFish server at: 0.0.0.0:3000 in development environment...
Writing log messages to: /Users/crigor/labs/log/development.log.
Press Ctrl+C to stop.

Missing the Rails 2.3.4 gem. Please `gem install -v=2.3.4 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
</pre>
<p>rails 2.3.4 is installed. In fact, jruby script/server works</p>
<pre class="brush: bash; light: true;">
$ jruby script/server
=&gt; Booting Mongrel
=&gt; Rails 2.3.4 application starting on http://0.0.0.0:3000
=&gt; Call with -d to detach
=&gt; Ctrl-C to shutdown server
</pre>
<p>I checked log/development.log and found an error on the run method on config/boot.rb.  </p>
<pre class="brush: plain; light: true;">
INFO: JRuby version is: 1.4.0
Feb 21, 2010 8:45:12 PM com.sun.grizzly.jruby.rack.RackApplicationPoolFactory getRackApplocationPool
SEVERE: exit
	from /Users/crigor/admoolabs/labs/config/boot.rb:38:in `run'
	from /Users/crigor/admoolabs/labs/config/boot.rb:11:in `boot!'
	from /Users/crigor/admoolabs/labs/config/boot.rb:110
	from /Users/crigor/admoolabs/labs/config/boot.rb:31:in `require'
	from /opt/local/share/java/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
	from /Users/crigor/admoolabs/labs/config/environment.rb:7
	from /Users/crigor/admoolabs/labs/config/environment.rb:31:in `require'
	from /opt/local/share/java/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
	from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/adapter/rails.rb:98:in `load_application'
	from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/adapter/rails.rb:75:in `initialize'
	from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/jruby/rack/rails.rb:25:in `new'
	from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/jruby/rack/rails.rb:25:in `new'
	from &lt;script&gt;:1
</pre>
<p>gem &#8216;rails&#8217;, version raised an error, thus the message &#8220;Missing the Rails 2.3.4 gem&#8221;. I&#8217;m sure that the gem is installed and jruby script/server works, so I inspected the error.</p>
<pre class="brush: plain; light: true;">
can't activate rack (~&gt; 1.0.0, runtime) for [&quot;actionpack-2.3.4&quot;, &quot;rails-2.3.4&quot;], already activated rack-1.1.0 for [&quot;glassfish-1.0.2-universal-java&quot;]
</pre>
<p>Look at that, it&#8217;s the familiar rubygems dependency problem. glassfish requires rack >= 0.4.0 but rubygems will activate the newest gem available which is version 1.1.0. rails 2.3.4 requires rack ~> 1.0.0, thus the conflict. This is the problem that bundler is trying to solve. Check my other <a href="http://blog.admoolabs.com/bundler-rubygems-again/">post</a> or the bundler <a href="http://github.com/carlhuda/bundler#readme">readme</a> for more details on the dependency problem. </p>
<p>The easiest way to get glassfish running is by removing rack 1.1.0. I&#8217;m not using it anyway. </p>
<pre class="brush: bash; light: true;">
$ sudo jgem uninstall rack

Select gem to uninstall:
 1. rack-1.0.1
 2. rack-1.1.0
 3. All versions
&gt; 2
Successfully uninstalled rack-1.1.0

$ jruby -S glassfish
Starting GlassFish server at: 0.0.0.0:3000 in development environment...
Writing log messages to: /Users/crigor/admoolabs/labs/log/development.log.
Press Ctrl+C to stop.
</pre>
<p>Go to localhost:3000, click &#8220;About your application’s environment&#8221; and check development.log</p>
<pre class="brush: plain; light: true;">
Feb 21, 2010 9:03:38 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO: 

Processing Rails::InfoController#properties (for 0:0:0:0:0:0:0:1%0 at 2010-02-21 21:03:38) [GET]

Feb 21, 2010 9:03:38 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO:   SQL (28.0ms)   SELECT version FROM schema_migrations

Feb 21, 2010 9:03:38 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO: Completed in 302ms (View: 57, DB: 28) | 200 OK [http://localhost/rails/info/properties]
</pre>
<p>In the future, I will try bundler or loading the gems myself. I already tried this <a href="http://blog.admoolabs.com/bundler-rubygems-again/">before</a> with ruby 1.8.7 when rails 2.3.5 wasn&#8217;t working with bundler 0.9.4.</p>
<p>Please share in the comments if you have other ways of running your jruby apps. Are you using glassfish or a different java app server?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.admoolabs.com/jruby-glassfish-ge/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bundler and Rubygems Again</title>
		<link>http://blog.admoolabs.com/bundler-rubygems-again/</link>
		<comments>http://blog.admoolabs.com/bundler-rubygems-again/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 17:18:23 +0000</pubDate>
		<dc:creator>Christopher Rigor</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[bundler]]></category>
		<category><![CDATA[rubygems]]></category>

		<guid isPermaLink="false">http://blog.admoolabs.com/?p=165</guid>
		<description><![CDATA[On my previous post, I showed you how to use bundler with rails 2.3.5. Bundler is used to install the gems, and rubygems is used to load the gems. Bundler as of version 0.9.4 doesn&#8217;t work with rails 2.3.5.
Since rubygems is used to load the gems, you might still encounter dependency resolution issues. This situation [...]]]></description>
			<content:encoded><![CDATA[<p>On my <a href="http://blog.admoolabs.com/using-bundler-0-9-4-with-rails-2-3-5/">previous post</a>, I showed you how to use bundler with rails 2.3.5. Bundler is used to install the gems, and rubygems is used to load the gems. Bundler as of version 0.9.4 doesn&#8217;t work with rails 2.3.5.</p>
<p>Since rubygems is used to load the gems, you might still encounter dependency resolution issues. This situation is described in the <a href="http://github.com/carlhuda/bundler#readme">readme</a> of bundler. Let&#8217;s say you have the following gems</p>
<p>actionmailer 2.3.4<br />
activemerchant 1.5.0<br />
activesupport 2.3.5, 2.3.4</p>
<p>Activemerchant needs activesupport >= 2.3.2. When you require activemerchant, it will activate the latest version that meets that requirement which is 2.3.5. Actionmailer on the other hand needs activesupport = 2.3.4. When rubygems tries to activate activesupport 2.3.4, it will raise an error.</p>
<pre class="brush: ruby; light: true;">
$ irb
irb(main):001:0&gt; require 'rubygems'
=&gt; true
irb(main):002:0&gt; gem 'activemerchant'
=&gt; true
irb(main):003:0&gt; gem 'actionmailer'
Gem::LoadError: can't activate activesupport (= 2.3.4, runtime) for [&quot;actionpack-2.3.4&quot;, &quot;actionmailer-2.3.4&quot;], already activated activesupport-2.3.5 for [&quot;activemerchant-1.5.0&quot;]
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:280:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:296:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `each'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:296:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `each'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:68:in `gem'
	from (irb):3
irb(main):004:0&gt;
</pre>
<p>Even if bundler installs the correct versions to vendor/bundler_gems, the presence of activesupport 2.3.5 in the system will cause an error. Another solution I tried is managing the load path by hand.</p>
<p>On config/preinitializer.rb</p>
<pre class="brush: ruby; light: true;">
bundler_gems = File.expand_path('../../vendor/bundler_gems/gems', __FILE__)
if File.exist?(bundler_gems)
  Dir[&quot;#{bundler_gems}/*/lib&quot;].each { |path| $:.unshift(path) }
end
</pre>
<p>This works if you use require instead of gem.</p>
<pre class="brush: ruby; light: true;">
$ irb
irb(main):001:0&gt; bundler_gems = File.expand_path('/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems')
=&gt; &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems&quot;
irb(main):002:0&gt; if File.exist?(bundler_gems)
irb(main):003:1&gt;   Dir[&quot;#{bundler_gems}/*/lib&quot;].each { |path| $:.unshift(path) }
irb(main):004:1&gt; end
=&gt; [&quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/actionmailer-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/actionpack-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activemerchant-1.5.0/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activerecord-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activeresource-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activesupport-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/builder-2.1.2/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/bundler-0.9.5/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rack-1.0.1/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rails-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rake-0.8.7/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/sqlite3-ruby-1.2.5/lib&quot;]
irb(main):005:0&gt; require 'rubygems'
=&gt; true
irb(main):006:0&gt; require 'active_merchant'
=&gt; true
irb(main):007:0&gt; require 'action_mailer'
=&gt; [&quot;MailHelper&quot;, &quot;Text&quot;, &quot;ActionMailer&quot;]
</pre>
<pre class="brush: ruby; light: true;">
$ irb
irb(main):001:0&gt; bundler_gems = File.expand_path('/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems')
=&gt; &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems&quot;
irb(main):002:0&gt; if File.exist?(bundler_gems)
irb(main):003:1&gt;   Dir[&quot;#{bundler_gems}/*/lib&quot;].each { |path| $:.unshift(path) }
irb(main):004:1&gt; end
=&gt; [&quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/actionmailer-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/actionpack-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activemerchant-1.5.0/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activerecord-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activeresource-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activesupport-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/builder-2.1.2/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/bundler-0.9.5/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rack-1.0.1/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rails-2.3.4/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rake-0.8.7/lib&quot;, &quot;/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/sqlite3-ruby-1.2.5/lib&quot;]
irb(main):005:0&gt; require 'rubygems'
=&gt; true
irb(main):006:0&gt; gem 'activemerchant'
=&gt; true
irb(main):007:0&gt; gem 'actionmailer'
Gem::LoadError: can't activate activesupport (= 2.3.4, runtime) for [&quot;actionpack-2.3.4&quot;, &quot;actionmailer-2.3.4&quot;], already activated activesupport-2.3.5 for [&quot;activemerchant-1.5.0&quot;]
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:280:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:296:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `each'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:296:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `each'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:68:in `gem'
	from (irb):7
	from /opt/local/lib/ruby/1.8/i686-darwin10/rbconfig.rb:132
</pre>
<p>Require works because I added the lib/ directories to the load path. If a file exists on the load path, require will not activate the gem. It will just load the file. If gems use gem &#8216;activesupport&#8217; before require &#8216;active_support&#8217;, then we&#8217;ll be in trouble. This is not the ideal solution I&#8217;m looking for but it&#8217;s close. On my next post, I&#8217;ll discuss using &#8216;fake&#8217; rubygems.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.admoolabs.com/bundler-rubygems-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Bundler 0.9.4 with Rails 2.3.5</title>
		<link>http://blog.admoolabs.com/using-bundler-0-9-4-with-rails-2-3-5/</link>
		<comments>http://blog.admoolabs.com/using-bundler-0-9-4-with-rails-2-3-5/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 14:12:44 +0000</pubDate>
		<dc:creator>Christopher Rigor</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[bundler]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.admoolabs.com/?p=160</guid>
		<description><![CDATA[Bundler works well with rails 3 beta but it doesn&#8217;t work with rails 2.3.5 yet. Here&#8217;s a simple way to use the gems installed by bundler.
Let&#8217;s create a rails app named labs.

$ rails labs
$ cd labs
$ ./script/console
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails [...]]]></description>
			<content:encoded><![CDATA[<p>Bundler works well with rails 3 beta but it doesn&#8217;t work with rails 2.3.5 yet. Here&#8217;s a simple way to use the gems installed by bundler.</p>
<p>Let&#8217;s create a rails app named labs.</p>
<pre class="brush: bash; auto-links: false; light: true;">
$ rails labs
$ cd labs
$ ./script/console
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed
</pre>
<p>As you can see, the rails 2.3.5 gem is missing. We will use bundler to install the gems to vendor/bundler_gems.</p>
<pre class="brush: bash; auto-links: false; light: true;">
$ vi Gemfile
</pre>
<pre class="brush: ruby; auto-links: false; light: true;">
source &quot;http://gemcutter.org&quot;
gem &quot;rails&quot;, &quot;2.3.5&quot;
gem &quot;sqlite3-ruby&quot;, :require =&gt; &quot;sqlite3&quot;
</pre>
<pre class="brush: bash; auto-links: false; light: true;">
$ bundle install vendor/bundler_gems
Fetching source index from http://gemcutter.org
Resolving dependencies
Installing actionmailer (2.3.5) from rubygems repository at http://gemcutter.org
Installing actionpack (2.3.5) from rubygems repository at http://gemcutter.org
Installing activerecord (2.3.5) from rubygems repository at http://gemcutter.org
Installing activeresource (2.3.5) from rubygems repository at http://gemcutter.org
Installing activesupport (2.3.5) from rubygems repository at http://gemcutter.org
Installing rack (1.0.1) from rubygems repository at http://gemcutter.org
Installing rails (2.3.5) from rubygems repository at http://gemcutter.org
Installing rake (0.8.7) from rubygems repository at http://gemcutter.org
Installing sqlite3-ruby (1.2.5) from rubygems repository at http://gemcutter.org with native extensions
Your bundle is complete!
</pre>
<pre class="brush: bash; auto-links: false; light: true;">
$ ./script/console
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed
</pre>
<p>The gem is still missing. Of course, the app doesn&#8217;t know where the gems are located.</p>
<p>We used bundler to install the gems, and in the future, we will use bundler to load the gems. Until then, we will use rubygems to load the gems. Create config/preinitializer.rb and set GEM_HOME.</p>
<pre class="brush: bash; auto-links: false; light: true;">
$ vi config/preinitializer.rb
</pre>
<pre class="brush: ruby; auto-links: false; light: true;">
ENV[&quot;GEM_HOME&quot;] = File.expand_path('../../vendor/bundler_gems', __FILE__)
</pre>
<pre class="brush: bash; auto-links: false; light: true;">
$ ./script/console
Loading development environment (Rails 2.3.5)
&gt;&gt; Rails.version
=&gt; &quot;2.3.5&quot;
&gt;&gt; Rack.version
=&gt; &quot;1.0&quot;
&gt;&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.admoolabs.com/using-bundler-0-9-4-with-rails-2-3-5/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How I Use Bundler</title>
		<link>http://blog.admoolabs.com/how-i-use-bundler/</link>
		<comments>http://blog.admoolabs.com/how-i-use-bundler/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 06:48:15 +0000</pubDate>
		<dc:creator>Christopher Rigor</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.admoolabs.com/?p=149</guid>
		<description><![CDATA[You probably heard that rails 3 beta is out and you want to try it. The instructions tell you to install the gems

gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
gem install rails --pre

Here, I&#8217;ll give you an alternative to installing rails 3 beta using bundler 0.9.3. This is for [...]]]></description>
			<content:encoded><![CDATA[<p>You probably heard that rails 3 beta is out and you want to try it. The instructions tell you to install the gems</p>
<pre class="brush: bash; auto-links: false; light: true;">
gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
gem install rails --pre
</pre>
<p>Here, I&#8217;ll give you an alternative to installing rails 3 beta using bundler 0.9.3. This is for those who don&#8217;t want to mix the rails 3 gems with their system gems, or who don&#8217;t want to use rubygems. Well you still need rubygems to install bundler.</p>
<pre class="brush: bash; auto-links: false; light: true;">
gem install bundler
</pre>
<p>After that, we create a gemfile on a directory that I&#8217;ll name &#8216;envs&#8217;.</p>
<pre class="brush: bash; auto-links: false; light: true;">
$ mkdir envs
$ cd envs
$ vi Gemfile
</pre>
<pre class="brush: ruby; auto-links: false; light: true;">
source &quot;http://gemcutter.org&quot;
gem &quot;rails&quot;, &quot;3.0.0.beta&quot;
</pre>
<pre class="brush: bash; auto-links: false; light: true;">
$ bundle install r3b
Resolving dependencies
Installing abstract (1.0.0) from rubygems repository at http://gemcutter.org
Installing actionmailer (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing actionpack (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activemodel (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activerecord (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activeresource (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activesupport (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing arel (0.2.1) from rubygems repository at http://gemcutter.org
Installing builder (2.1.2) from rubygems repository at http://gemcutter.org
Installing bundler (0.9.3) from rubygems repository at http://gemcutter.org
Installing erubis (2.6.5) from rubygems repository at http://gemcutter.org
Installing i18n (0.3.3) from rubygems repository at http://gemcutter.org
Installing mail (2.1.2) from rubygems repository at http://gemcutter.org
Installing memcache-client (1.7.8) from rubygems repository at http://gemcutter.org
Installing mime-types (1.16) from rubygems repository at http://gemcutter.org
Installing rack (1.1.0) from rubygems repository at http://gemcutter.org
Installing rack-mount (0.4.7) from rubygems repository at http://gemcutter.org
Installing rack-test (0.5.3) from rubygems repository at http://gemcutter.org
Installing rails (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing railties (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing rake (0.8.7) from rubygems repository at http://gemcutter.org
Installing text-format (1.0.0) from rubygems repository at http://gemcutter.org
Installing text-hyphen (1.0.0) from rubygems repository at http://gemcutter.org
Installing thor (0.13.0) from rubygems repository at http://gemcutter.org
Installing tzinfo (0.3.16) from rubygems repository at http://gemcutter.org
Your bundle is complete!
</pre>
<pre class="brush: bash; auto-links: false; light: true;">
$ bundle show
Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.0.beta)
* actionpack (3.0.0.beta)
* activemodel (3.0.0.beta)
* activerecord (3.0.0.beta)
* activeresource (3.0.0.beta)
* activesupport (3.0.0.beta)
* arel (0.2.1)
* builder (2.1.2)
* bundler (0.9.3)
* erubis (2.6.5)
* i18n (0.3.3)
* mail (2.1.2)
* memcache-client (1.7.8)
* mime-types (1.16)
* rack (1.1.0)
* rack-mount (0.4.7)
* rack-test (0.5.3)
* rails (3.0.0.beta)
* railties (3.0.0.beta)
* rake (0.8.7)
* text-format (1.0.0)
* text-hyphen (1.0.0)
* thor (0.13.0)
* tzinfo (0.3.16)
</pre>
<p>I like to create my rails apps on a separate directory outside of envs. We need to specify the location of the Gemfile.</p>
<pre class="brush: bash; auto-links: false; light: true;">
$ cd ..
$ bundle show
The default Gemfile was not found
</pre>
<p>We need to specify the location of the Gemfile.</p>
<pre class="brush: bash; auto-links: false; light: true;">
$ export BUNDLE_GEMFILE=&quot;/Users/crigor/admoolabs/envs/Gemfile&quot;
$ bundle show
Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.0.beta)
* actionpack (3.0.0.beta)
...
</pre>
<p>You can now run the rails command using bundle exec.</p>
<pre class="brush: bash; auto-links: false; light: true;">
$ rails -v
Rails 2.3.4
$ bundle exec rails -v
Rails 3.0.0.beta
</pre>
<p>Let&#8217;s create the rails app named labsapp.</p>
<pre class="brush: bash; auto-links: false; light: true;">
$ bundle exec rails labsapp
      create
      create  README
      create  .gitignore
      create  Rakefile
      create  config.ru
      create  Gemfile
      create  app
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/models
      create  app/views/layouts
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookie_verification_secret.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/session_store.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  log
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  public/images
      create  public/images/rails.png
      create  public/stylesheets
      create  public/stylesheets/.gitkeep
      create  public/javascripts
      create  public/javascripts/application.js
      create  public/javascripts/controls.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/effects.js
      create  public/javascripts/prototype.js
      create  public/javascripts/rails.js
      create  script
      create  script/rails
      create  test
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  test/fixtures
      create  test/functional
      create  test/integration
      create  test/unit
      create  tmp
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
</pre>
<p>Let&#8217;s run the console.</p>
<pre class="brush: bash; auto-links: false; light: true;">
$ cd labsapp
$ ./script/rails c
Loading development environment (Rails 3.0.0.beta)
irb(main):001:0&gt; Rails.version
=&gt; &quot;3.0.0.beta&quot;
irb(main):002:0&gt; Rack.version
=&gt; &quot;1.1&quot;
</pre>
<p>You now have the rails 3 gems separate from rails 2.x gems. Only the rails 2.x gems are installed on the system.</p>
<pre class="brush: bash; auto-links: false; light: true;">
$ gem list rails
rails (2.3.4, 2.3.2, 2.2.2, 2.1.1, 2.1.0)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.admoolabs.com/how-i-use-bundler/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>uninitialized constant PGconn</title>
		<link>http://blog.admoolabs.com/uninitialized-constant-activerecord-connectionadapters-postgresqladapter-pgconn/</link>
		<comments>http://blog.admoolabs.com/uninitialized-constant-activerecord-connectionadapters-postgresqladapter-pgconn/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 15:36:09 +0000</pubDate>
		<dc:creator>Christopher Rigor</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.admoolabs.com/?p=143</guid>
		<description><![CDATA[I&#8217;m successfully using Postgres for development. My stack includes ruby 1.8.7, rails 2.3.4, and pg 0.8.0. One day, I get an error

NameError: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn

I didn&#8217;t update Postgres or the pg gem so I don&#8217;t see a reason for it to stop working. Then I remember that I installed jruby and installed the activerecord adapater. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m successfully using Postgres for development. My stack includes ruby 1.8.7, rails 2.3.4, and pg 0.8.0. One day, I get an error</p>
<pre class="brush: plain; light: true;">
NameError: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn
</pre>
<p>I didn&#8217;t update Postgres or the pg gem so I don&#8217;t see a reason for it to stop working. Then I remember that I installed jruby and installed the activerecord adapater. Instead of using jgem install, I used gem install. This installed the gems (activerecord-jdbc-adapter, activerecord-jdbcmysql-adapter and jdbc-mysql) on my ruby 1.8.7 system. I left the gems installed thinking they wouldn&#8217;t cause any error.</p>
<p>So, if you encounter uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn check if you have the jdbc adapter gems for jruby.</p>
<p>I hope this helps someone.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.admoolabs.com/uninitialized-constant-activerecord-connectionadapters-postgresqladapter-pgconn/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Capistrano 2.5.11 Latest Release Workaround</title>
		<link>http://blog.admoolabs.com/capistrano-2-5-11-latest-release-workaround/</link>
		<comments>http://blog.admoolabs.com/capistrano-2-5-11-latest-release-workaround/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 09:54:18 +0000</pubDate>
		<dc:creator>Christopher Rigor</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.admoolabs.com/?p=139</guid>
		<description><![CDATA[A recent commit in Capistrano broke some of the deploys. The latest_release directory becomes the oldest release instead of the most recent. Some of the effects I&#8217;ve seen are: 1) rake db:migrate is run on the oldest release 2) deploy:cleanup deletes the most recent releases.
When you deploy, and the number of releases directories exceed keep_releases, [...]]]></description>
			<content:encoded><![CDATA[<p>A recent <a href="http://github.com/capistrano/capistrano/commit/92941e855d70a5778eb094a972fdf43c70802b95">commit</a> in Capistrano broke some of the deploys. The latest_release directory becomes the oldest release instead of the most recent. Some of the effects I&#8217;ve seen are: 1) rake db:migrate is run on the oldest release 2) deploy:cleanup deletes the most recent releases.</p>
<p>When you deploy, and the number of releases directories exceed keep_releases, deploy:cleanup would delete the directory that  you&#8217;re trying to deploy. You&#8217;ll end up with current that symlinks to a missing directory.</p>
<p>You can follow the ticket on <a href="https://capistrano.lighthouseapp.com/projects/8716/tickets/88-getting-the-newest-directory">lighthouse</a>. In the meantime, you can use a workaround. On your deploy.rb, add</p>
<pre class="brush: ruby; light: true;">
set :releases, lambda { capture(&quot;ls -x #{releases_path}&quot;).split.sort }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.admoolabs.com/capistrano-2-5-11-latest-release-workaround/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Installing Nginx with Passenger on Snow Leopard Using MacPorts</title>
		<link>http://blog.admoolabs.com/nginx-passenger-snow-leopard-macports/</link>
		<comments>http://blog.admoolabs.com/nginx-passenger-snow-leopard-macports/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 15:06:51 +0000</pubDate>
		<dc:creator>Christopher Rigor</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[passenger]]></category>

		<guid isPermaLink="false">http://blog.admoolabs.com/?p=110</guid>
		<description><![CDATA[Install MacPorts if you don&#8217;t have it. 
Download and install the Portfile

git clone git://github.com:crigor/admoolabs-ports.git ports
cd ports/nginx-0.7.64-passenger-2.2.8
sudo port -v install

You need to have ruby installed to compile passenger. In case you don&#8217;t have ruby, you can also get it from macports. 
sudo port -v install ruby
If you have an older version of nginx installed using macports, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.macports.org/install.php">Install MacPorts</a> if you don&#8217;t have it. </p>
<p>Download and install the Portfile</p>
<pre class="brush: bash; auto-links: false; light: true;">
git clone git://github.com:crigor/admoolabs-ports.git ports
cd ports/nginx-0.7.64-passenger-2.2.8
sudo port -v install
</pre>
<p>You need to have ruby installed to compile passenger. In case you don&#8217;t have ruby, you can also get it from macports. </p>
<pre class="brush: bash; light: true;">sudo port -v install ruby</pre>
<p>If you have an older version of nginx installed using macports, it might move nginx.conf to nginx.conf.altered. Copy it back to nginx.conf if you need it. You can also use this <a href="http://gist.github.com/258789">nginx.conf</a>.</p>
<p>Edit /opt/local/etc/nginx.conf and add the following lines inside http {}</p>
<pre class="brush: bash; light: true;">
passenger_root /opt/local/lib/passenger;
passenger_ruby /opt/local/bin/ruby;
</pre>
<p>Change the ruby path if you&#8217;re not using ruby from macports.</p>
<p>For each rails app, you need to add the following, also inside http {}</p>
<pre class="brush: bash; auto-links: false; light: true;">
server {
  server_name labs.local;
  root /Users/crigor/admoolabs/labs/public;
  access_log /opt/local/var/log/nginx/labs.local.access.log;
  error_log /opt/local/var/log/nginx/labs.local.error.log;
  passenger_enabled on;
  rails_env development;
}
</pre>
<p>Check if your syntax is correct.</p>
<pre class="brush: bash; light: true;">
sudo /opt/local/sbin/nginx -t
</pre>
<p>If it is, you&#8217;ll see</p>
<pre class="brush: bash; light: true;">
the configuration file /opt/local/etc/nginx/nginx.conf syntax is ok
configuration file /opt/local/etc/nginx/nginx.conf test is successful
</pre>
<p>Start nginx with</p>
<pre class="brush: bash; light: true;">
sudo /opt/local/sbin/nginx
</pre>
<p>You won&#8217;t get any output if it starts correctly. Check if nginx is running</p>
<pre class="brush: bash; light: true;">
ps -e | grep nginx -i
(You should see something like these lines)
nginx: master process /opt/local/sbin/nginx
nginx: worker process
PassengerNginxHelperServer /opt/local/lib/passenger /opt/local/bin/ruby 3 4 0 6 0 300 1 nobody 4294967294 4294967294 /tmp/passenger.10755
</pre>
<p>MacPorts added a startup item which is disabled by default. To start it,</p>
<pre class="brush: bash; light: true;">
sudo launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist
</pre>
<p>You can stop nginx with</p>
<pre class="brush: bash; light: true;">
sudo launchctl stop org.macports.nginx
</pre>
<p>but it would just be started right away. If you want it to remain stopped, use</p>
<pre class="brush: bash; light: true;">
sudo launchctl unload /Library/LaunchDaemons/org.macports.nginx.plist
</pre>
<p>When you make changes to the config, reload the config with</p>
<pre class="brush: bash; light: true;">
sudo /opt/local/sbin/nginx -s reload
</pre>
<p>Check the other nginx options using
<pre class="brush: bash; light: true;">/opt/local/sbin/nginx -h</pre>
<p>One more thing&#8230;<br />
When you add a rails or rack app, you need to specify a different server_name. You need to add it to /etc/hosts </p>
<pre class="brush: bash; light: true;">
127.0.0.1 localhost labs.local
</pre>
<p>Don&#8217;t you think it would be great if you can handle this automatically? Me too. Stay tuned for more. This shouldn&#8217;t be a <del>pane</del> pain. <img src='http://blog.admoolabs.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.admoolabs.com/nginx-passenger-snow-leopard-macports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install PHP 5.2 on Ubuntu Dapper</title>
		<link>http://blog.admoolabs.com/install-php-52-ubuntu-dapper/</link>
		<comments>http://blog.admoolabs.com/install-php-52-ubuntu-dapper/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 14:27:26 +0000</pubDate>
		<dc:creator>Christopher Rigor</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[dapper]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.admoolabs.com/?p=105</guid>
		<description><![CDATA[The repositories on Ubuntu Dapper don&#8217;t have php 5.2. To install php 5.2, I added the hardy repositories.
vi /etc/apt/sources.list
add the repositories
deb http://us.archive.ubuntu.com/ubuntu/ hardy main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ hardy main restricted
then run
sudo apt-get update
sudo apt-get install php5
This tried to install and upgrade a lot of packages including apache. I really needed php 5.2 and since the server [...]]]></description>
			<content:encoded><![CDATA[<p>The repositories on Ubuntu Dapper don&#8217;t have php 5.2. To install php 5.2, I added the hardy repositories.</p>
<p><code>vi /etc/apt/sources.list</code></p>
<p>add the repositories<br />
<code>deb http://us.archive.ubuntu.com/ubuntu/ hardy main restricted<br />
deb-src http://us.archive.ubuntu.com/ubuntu/ hardy main restricted</code></p>
<p>then run<br />
<code>sudo apt-get update<br />
sudo apt-get install php5</code></p>
<p>This tried to install and upgrade a lot of packages including apache. I really needed php 5.2 and since the server is a development server, I accepted all the changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.admoolabs.com/install-php-52-ubuntu-dapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
