Friday September 18, 2009
Free Rails/GlassFish Webinar with live Q&A: Sep 23, 2009,10am PT
Content available at: http://blog.arungupta.me/2009/09/free-railsglassfish-webinar-with-live-qa-sep-23-200910am-pt/
Posted by Arun Gupta in General | Comments[0]
|
|
|
|
|
Wednesday August 12, 2009
TOTD #92: Session Failover for Rails applications running on GlassFish
The GlassFish
High Availability
allows to setup a cluster of GlassFish instances and achieve highly
scalable architecture using in-memory session state replication. This
cluster can be very
easily created and tested using the "clusterjsp" sample
bundled with GlassFish. Here are some clustering related entries
published on this blog so far:
| ~/samples/jruby/session >~/tools/jruby/bin/jruby
script/generate controller home index JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL exists app/controllers/ exists app/helpers/ create app/views/home exists test/functional/ create test/unit/helpers/ create app/controllers/home_controller.rb create test/functional/home_controller_test.rb create app/helpers/home_helper.rb create test/unit/helpers/home_helper_test.rb create app/views/home/index.html.erb |
| class HomeController < ApplicationController include Java def index @server_served = servlet_request.get_server_name @port = servlet_request.get_server_port @instance = java.lang.System.get_property "com.sun.aas.instanceName" @server_executed = java.net.InetAddress.get_local_host().get_host_name() @ip = java.net.InetAddress.get_local_host().get_host_address @session_id = servlet_request.session.get_id @session_created = servlet_request.session.get_creation_time @session_last_accessed = servlet_request.session.get_last_accessed_time @session_inactive = servlet_request.session.get_max_inactive_interval if (params[:name] != nil) servlet_request.session[params[:name]] = params[:value] end @session_values = "" value_names = servlet_request.session.get_attribute_names unless (value_names.has_more_elements) @session_values = "<br>No parameter entered for this request" else @session_values << "<UL>" while (value_names.has_more_elements) param = value_names.next_element unless (param.starts_with?("__")) value = servlet_request.session.get_attribute(param) @session_values << "<LI>" + param + " = " + value + "</LI>" end end @session_values << "</UL>" end end def adddata servlet_request.session.set_attribute(params[:name], params[:value]) render :action => "index" end def cleardata servlet_request.session.invalidate render :action => "index" end end |
| <h1>Home#index</h1> <p>Find me in app/views/home/index.html.erb</p> <B>HttpSession Information:</B> <UL> <LI>Served From Server: <b><%= @server_served %></b></LI> <LI>Server Port Number: <b><%= @port %></b></LI> <LI>Executed From Server: <b><%= @server_executed %></b></LI> <LI>Served From Server instance: <b><%= @instance %></b></LI> <LI>Executed Server IP Address: <b><%= @ip %></b></LI> <LI>Session ID: <b><%= @session_id %></b></LI> <LI>Session Created: <%= @session_created %></LI> <LI>Last Accessed: <%= @session_last_accessed %></LI> <LI>Session will go inactive in <b><%= @session_inactive %> seconds</b></LI> </UL> <BR> <% form_tag "/session/home/index" do %> <label for="name">Name of Session Attribute:</label> <%= text_field_tag :name, params[:name] %><br> <label for="value">Value of Session Attribute:</label> <%= text_field_tag :value, params[:value] %><br> <%= submit_tag "Add Session Data" %> <% end %> <% form_tag "/session/home/cleardata" do %> <%= submit_tag "Clear Session Data" %> <% end %> <% form_tag "/session/home/index" do %> <%= submit_tag "Reload Page" %> <% end %> <BR> <B>Data retrieved from the HttpSession: </B> <%= @session_values %> |
| ~/samples/jruby/session >~/tools/jruby/bin/jruby -S warble
war:webxml mkdir -p tmp/war/WEB-INF ~/samples/jruby/session >cp tmp/war/WEB-INF/web.xml config/ |
| <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> |
| <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> |
| <distributable/> |
| ~/samples/jruby/session >~/tools/jruby/bin/jruby -S warble mkdir -p tmp/war/WEB-INF/gems/specifications cp /Users/arungupta/tools/jruby-1.3.0/lib/ruby/gems/1.8/specifications/rails-2.3.2.gemspec tmp/war/WEB-INF/gems/specifications/rails-2.3.2.gemspec . . . mkdir -p tmp/war/WEB-INF cp config/web.xml tmp/war/WEB-INF jar cf session.war -C tmp/war . |
| ~/samples/jruby/session >asadmin deploy --target wines --port 5048 --availabilityenabled=true session.war |








Posted by Arun Gupta in General | Comments[2]
|
|
|
|
|
Monday August 03, 2009
TOTD #88: How add pagination to Rails - will_paginate
This Tip Of The Day (TOTD) explains
how to add pagination to your Rails application.
| ~/samples/jruby
>~/tools/jruby/bin/jruby
-S rails paginate ~/samples/jruby/paginate >~/tools/jruby/bin/jruby script/generate scaffold book title:string author:string ~/samples/jruby/paginate >sed s/'adapter: sqlite3'/'adapter: jdbcsqlite3'/ <config/database.yml >config/database.yml.new ~/samples/jruby/paginate >mv config/database.yml.new config/database.yml ~/samples/jruby/paginate >~/tools/jruby/bin/jruby -S rake db:migrate |
| #
Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html one: title: Ultramarathon Man Confessions of an All-Night Runner author: Dean Karnazes two: title: My Life on the Run author: Bart Yasso three: title: 50/50 Secrets I Learned Running 50 Marathons in 50 Days author: Dean Karnazes four: title: Born to Run author: Christopher Mcdougall five: title: Four Months to a Four-hour Marathon author: Dave Kuehls six: title: Galloway's Book on Running author: Jeff Galloway seven: title: Marathoning for Mortals author: John Bingham and Jenny Hadfield eight: title: Marathon You Can Do It! author: Jeff Galloway nine: title: Marathon The Ultimate Training Guide author: Hal Higdon ten: title: Running for Mortals author: John Bingham and Jenny Hadfield |
| ~/samples/jruby/paginate
>~/tools/jruby/bin/jruby
-S rake db:fixtures:load (in /Users/arungupta/samples/jruby/paginate) |
| ~/samples/jruby/paginate
>~/tools/jruby/bin/jruby
-S glassfish -l Starting GlassFish server at: 129.145.132.8:3000 in development environment... Writing log messages to: /Users/arungupta/samples/jruby/paginate/log/development.log. . . . Jul 29, 2009 2:06:44 PM com.sun.grizzly.scripting.pool.DynamicPool$1 run INFO: New instance created in 7,488 milliseconds |

| /tools/jruby
>./bin/jruby -S gem install will_paginate JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Successfully installed will_paginate-2.2.2 1 gem installed Installing ri documentation for will_paginate-2.2.2... Installing RDoc documentation for will_paginate-2.2.2... |
| require "will_paginate" |
| @books
= Book.paginate(:page => params[:page], :per_page => 5) #@books = Book.all |
| <%= will_paginate @books %> |


Posted by Arun Gupta in web2.0 | Comments[1]
|
|
|
|
|
Friday July 31, 2009
If you are using Warbler to create a WAR file of your application and
deploying on GlassFish
or any other Servlet container, then you are likely seeing the
following error during deployment:
| [#|2009-07-30T15:29:50.788-0700|SEVERE|sun-appserver2.1|javax.enterprise.system.container.web|_ThreadID=17; _ThreadName=httpWorkerThread-4848-0;_RequestID=1d7e8f18-1c9a-4924-bd0b-6a07eba425ba;|WebModule [/session]unable to create shared application instance org.jruby.rack.RackInitializationException: undefined method `new' for "Rack::Lock":String from /Users/arungupta/tools/glassfish/v2.1/glassfish/domains/domain1/applications/j2ee-modules/session/WEB-INF/gems/gems/actionpack-2.3.2/lib/ action_controller/middleware_stack.rb:116:in `inject' from /Users/arungupta/tools/glassfish/v2.1/glassfish/domains/domain1/applications/j2ee-modules/session/WEB-INF/gems/gems/actionpack-2.3.2/lib/ action_controller/middleware_stack.rb:116:in `build' from /Users/arungupta/tools/glassfish/v2.1/glassfish/domains/domain1/applications/j2ee-modules/session/WEB-INF/gems/gems/actionpack-2.3.2/lib/ action_controller/dispatcher.rb:82:in `initialize' . . . |
| # Additional Java .jar files to include.
Note that if .jar files are placed # in lib (and not otherwise excluded) then they need not be mentioned here. # JRuby and JRuby-Rack are pre-loaded in this list. Be sure to include your # own versions if you directly set the value # config.java_libs += FileList["lib/java/*.jar"] config.java_libs.delete_if {|f| f =~ /jruby-rack/ } config.java_libs += FileList["lib/jruby-rack*.jar"] |
| # Additional Java .jar files to include.
Note that if .jar files are placed # in lib (and not otherwise excluded) then they need not be mentioned here. # JRuby and JRuby-Rack are pre-loaded in this list. Be sure to include your # own versions if you directly set the value # config.java_libs += FileList["lib/java/*.jar"] config.java_libs.delete_if {|f| f =~ /jruby-rack/ || f =~ /jruby-complete/ } config.java_libs += FileList["lib/jruby-complete*.jar"] config.java_libs += FileList["lib/jruby-rack*.jar"] |
Posted by Arun Gupta in web2.0 | Comments[7]
|
|
|
|
|
Tuesday July 28, 2009
Track your running miles using JRuby, Ruby-on-Rails, GlassFish, NetBeans, MySQL, and YUI Charts
This blog introduces a new application that will provide basic tracking
of your running distance and generate charts to monitor progress. There
are numerous similar applications that are already available/hosted and
this is a very basic application. What's different about this ?
The first version of this application is built using JRuby,
Ruby-on-Rails, GlassFish Gem, MySQL, and NetBeans IDE. This combination
of technologies is a high quality Rails stack that is used in production
deploymnet at various places. Still nothing different ?
A similar version of this application
will be built using a variety of Web frameworks such as Java EE, Grails, Wicket, Spring and Struts2 (in
no particular order). The goal is to provide a similar application,
slightly bigger than "Hello World," built using different frameworks
and deploy on GlassFish.
Each framework will then be evaluated based upon the criteria ranging
from the basic principles of framework, ease-of-use in
design/development/testing/debugging/production of this web app,
database interaction, tools support, ability to add 3rd party
libraries, browser compatibility and other points.
An important point to note is that this is not an exhaustive
evaluation of different Web frameworks and the scope is limited only to
this application.
A complete list of frameworks planned is available here.
The criteria used to evaluate each framework is described here.
Your feedback in terms of Web frameworks and evaluation criteria is
highly appreciated. Please share your feedback on the users list.
Now the first version of application. The complete instructions to
check out and run the Rails version of
this application are available here.
Here are some charts generated using the application:

and

YUI is
used for all the charting capabilities.
And here is a short video that explains how the application work:
If you are a runner, check out the application and use it for tracking
your miles. A sample runlog is available in "test/fixtures/runlogs.yml"
and races in "test/fixtures/races.yml".
If you know Rails, please provide feedback if the application is DRY
and using the right set of helpers.
If you'd like the existing list of web frameworks to be pruned or
include another one to the list, let us know.
Share you feedback at users@runner.kenai.com.
Technorati: jruby
rubyonrails
glassfish
netbeans
mysql
yahoo
yui chart running miles framework
Posted by Arun Gupta in Running | Comments[2]
|
|
|
|
|
Thursday July 02, 2009
Rails on GlassFish - "most performant of all", "simpler and just works", "blazing speed"
Here are some quotes about running Rails applications on GlassFish from user@jruby
mailing list:
I find the glassfish gem
to be the most performant of all -- and I don't need to war-up my app.
I also have some mongrel
cluster stuff, but glassfish is simpler and just works.
Voila...blazing speed,
can handle lots of traffic. Note that I am also cominging into apache
from a dyndns name. So, whatever IP I have, I can go straight to
execution on the glassfish gem and NO warring up! What could be easier
deployment, or a faster execution?
It's running fantasticly
and performing like nothing I've seen before :) Completely stable
memory, no wirings or anything bad for 5 days now.. (with several
ab/htperf stresstests).
It's always exciting to get good endorsements of our efforts in the
GlassFish team :)
Other similar stories for using Rails/GlassFish in production are
described at rubyonrails+stories.
Technorati: glassfish
v3 gem rubyonrails
stories
jruby
Posted by Arun Gupta in web2.0 | Comments[3]
|
|
|
|
|
Tuesday June 16, 2009
TOTD #84: Using Apache + mod_proxy_balancer to load balance Ruby-on-Rails running on GlassFish
TOTD
#81 explained how to install/configure nginx for
load-balancing/front-ending a cluster of Rails application running on GlassFish
Gem. Another popular approach in the Rails community is to
use Apache HTTPD
+ mod_proxy_balancer.
A user asked the exact details of this
setup on the GlassFish
Gem Forum. This Tip
Of The Day (TOTD) will
clearly explain the steps.
| LoadModule proxy_balancer_module libexec/apache2/mod_proxy_balancer.so |
| <Proxy balancer://glassfishgem> BalancerMember http://localhost:3000 BalancerMember http://localhost:3001 BalancerMember http://localhost:3002 </Proxy> |
| ProxyPass / balancer://glassfishgem/ CustomLog /var/log/glassfishgem.log/apache_access_log combined |
| CustomLog /var/log/glassfishgem.log/apache_access_log combined |
| ~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e
production -c myapp Starting GlassFish server at: 10.0.177.178:3000 in production environment... Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log. Press Ctrl+C to stop. . . . ~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e production -c myapp -p 3001 Starting GlassFish server at: 10.0.177.178:3001 in production environment... Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log. Press Ctrl+C to stop. . . . ~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e production -c myapp -p 3002 Starting GlassFish server at: 10.0.177.178:3002 in production environment... Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log. Press Ctrl+C to stop. |
| ProxyPass /myapp/
balancer://glassfishgem/myapp/ |
| LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" \"%{BALANCER_WORKER_NAME}e\"" custom |
| CustomLog /var/log/glassfishgem.com/apache_access_log custom |
| ::1 - - [17/Jun/2009:10:53:53 -0700] "GET /runlogs
HTTP/1.1" 304 - "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5;
en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11"
"http://localhost:3002" ::1 - - [17/Jun/2009:10:54:04 -0700] "GET /runlogs HTTP/1.1" 200 621 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11" "http://localhost:3000" ::1 - - [17/Jun/2009:10:54:05 -0700] "GET /runlogs HTTP/1.1" 304 - "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11" "http://localhost:3001" |
Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
|
Wednesday June 10, 2009
OPIN Systems - Financial Application using JRuby-on-Rails on GlassFish
OPIN Systems
has chosen JRuby, Rails, and GlassFish for a
customer-facing financial
application. Why ? "Easy to setup Rails application and add more
intense logic in JRuby calls"
Learn more about it in this video:
Thanks to Ben Leadholm for the quick story! Check out other GlassFish Production Stories.
Check out Ben's
"Dude,
Where's my pass ?" entry:
Read several other Rails/GlassFish
success stories.
Technorati: conf
javaone
sanfrancisco
glassfish
rubyonrails
stories
Posted by Arun Gupta in General | Comments[1]
|
|
|
|
|
Friday May 15, 2009
Ruby-on-Rails and Ramaze production deployments on GlassFish
Published three new JRuby/GlassFish production deployment stories
in as many days:
Posted by Arun Gupta in General | Comments[0]
|
|
|
|
|
Wednesday May 06, 2009
Rails Conf 2009 Day 3 Trip Report
Attended a great talk by Michael
Bleigh on Twitter
on Rails. He has
built a gem, TwitterAuth,
that uses Twitter as authentication provider (OAuth or HTTP Basic)
which allows to to quickly and easily create
Twitter applications in Rails. In Michael's words "TwitterAuth makes Twitter Rails
apps stupid simple".
The talk built Twistener - a
Twitter application in Rails that shows how many tweepl are having a
conversation about you. A hosted version of
the application is available at twisteners.heroku.com.
The slides
and end result
of the code are always helpful.
In
a post-talk conversation he mentioned that all the gems are pure Ruby.
Any body willing to re-build the application and trying using JRuby and
GlassFish ?
And then attended Rails
3: Stepping off of the Golden Path by a "morally loose,
cheese eating surrender monkey", aka Matt Aimonetti :)
What are you going to get in Rails 3 ?
Rails Conf 2009 Day 3 - Chris's Keynote

An informal survey this morning at Rails Conf 2009
keynote showed:
40% Rails developers in startup
30% Rails developers in consulting
30% Rails developers work in internal projects
Engine Yard got a sponsor keynote slot and announced Flex - a cloud
computing platform on EC2 to host Rails applications. They also showed
one-button self-healing clusters. One of the speakers was particularly
scared (reminds me of my early days) and IRC#railsconf
had a pool of $125 to hug him on the stage :) Anyway, read more details
here.
The highlight of the morning was keynote by Chris Wanstrath (@defunkt). I
took multiple notes during the keynote but the transcript
has
all the details. The first part of the talk has good tips on how to
create a successful blog such as blog personality, template, killer
name and a sleek design, sparse side bar, consistency and structure,
and many others.
There was a good bashing of SourceForge towards 60% in the talk. Chris
gave a suggestion to SourceForge:
They should cut their
registration process down to a single page, remove the 200 character
"please host my project" plea, be more lenient on the categorization,
suggest an open source license for you, then allow you to change any of
these things after your project has been created.
And there are other interesting ones too. Read the full text
and enjoy!
Here were some of the Q&As at the end of keynote ...
Q. What was your inspiration for github ?
A. Inspiration is coding, doing open source software all the time,
downloading patches, relative paths were getitng in the way to coding.
Source forge registration page is too long. github is very simple for
anything code related that you want to put there.
Q. You develop these interesting pieces of software, have a job, play
guitar,
create pieces of music, drum music, how you do this in one lifetime ?
A. I outsource most of it. All of us do it, I post my music and code on
the Internet, watch a lot of TV. I'm into sharing on github. Don't have
a better work ethic, just talk a lot.
Q. What do you watch on the TV ?
A. Legend of the secret
Q. Built a bunch of tools used by non-Rubyists, how can we promote Ruby
there ?
A. RubyGems is one reason I fell in love with Ruby. Remove the friction
and lower the barrier to entry.
Q. Focus github around the code/community, it helps around the people,
opposite of Source Forge/Ruby Forge
A. Github is like facebook for code development.
Technorati: conf
railsconf
git github lasvegas
rubyonrails
Posted by Arun Gupta in General | Comments[0]
|
|
|
|
|
Tuesday May 05, 2009
Rails Conf 2009 Day 2 Trip Report
This is a follow up post from David's
keynote.
| Attended Women
in Rails
panel discussion. The panel, Sarah
Mei, Lori
Olson, and Desi
McAdam (from L to R), had a very interesting discussion
around
the genuine problems and possible solutions of involving more women in
Rails community. |
![]() |
I presented on Develop with Pleasure, Deploy with Fun: GlassFish and NetBeans for a better Rails experience, slides here. The several concepts in the talk are explained in the following bullets: |
![]() |
The next talk of the day was JRuby: State of the Art |
| Later in the evening, Brian Helmkamp, Aman Gupta, Luis Navena, Pat Allan, Dan Kubb, and John Nunemaker were awarded Ruby Heroes Award! |
![]() |
And the keynote by Tim Ferris,
lets not talk about it ;-) I edited pictures, authored my blog, caught
up
on email/RSS during the keynote. #railconf on IRC and twitter
were way more fun! Check the live ratings. "1" was the lowest rating that could be given anyway! |
Sea Change Affinity - Why JRuby/GlassFish ?
At Rails Conf
2009, Jay
McGaffigan from Sea
Change talked about why they choose JRuby/GlassFish for their
product Affinity.
Here are some of the reasons he quoted:
Posted by Arun Gupta in web2.0 | Comments[1]
|
|
|
|
|
Monday May 04, 2009
Rails Conf 2009 - Day 1 Trip Report
Rails Conf 2009 started this morning. The first day consists of morning
and afternoon tutorials.
I attended Nick Sieger's JRuby
on Rails tutorial, the slides are available.
A survey in the room showed:
| run
lambda { |env| [ 200, { 'Content-Length' => '2', 'Content-Type' => 'text/html', }, ["hi"] ] } |
| ~/samples/railsconf/sinatra/basic-rack
>~/tools/jruby/bin/jruby
-S rackup [2009-05-04 13:40:18] INFO WEBrick 1.3.1 [2009-05-04 13:40:18] INFO ruby 1.8.6 (2009-03-16) [java] [2009-05-04 13:40:18] INFO WEBrick::HTTPServer#start: pid=90964 port=9292 127.0.0.1 - - [04/May/2009 13:40:27] "GET / HTTP/1.1" 200 2 0.0160 127.0.0.1 - - [04/May/2009 13:40:27] "GET /favicon.ico HTTP/1.1" 200 2 0.0060 127.0.0.1 - - [04/May/2009 13:40:30] "GET /favicon.ico HTTP/1.1" 200 2 0.0100 |
| App
= lambda { |env| [ 200, { 'Content-Length' => '2', 'Content-Type' => 'text/html', }, ["hi"] ] } |
| ~/samples/railsconf/sinatra/basic-rack
>~/tools/jruby/bin/jruby
-S rackup app.rb [2009-05-04 13:43:57] INFO WEBrick 1.3.1 [2009-05-04 13:43:57] INFO ruby 1.8.6 (2009-03-16) [java] [2009-05-04 13:43:57] INFO WEBrick::HTTPServer#start: pid=90990 port=9292 127.0.0.1 - - [04/May/2009 13:44:09] "GET / HTTP/1.1" 200 2 0.0110 |
| class
BasicRack def call(env) body = "Hello from a class" [ 200, { 'Content-Length' => body.size.to_s, 'Content-Type' => 'text/html', }, [body] ] end end run BasicRack.new |

| ~/samples/railsconf/sinatra/basic-rack
>~/tools/jruby/bin/jruby -S gem install shotgun JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Successfully installed configuration-0.0.5 Successfully installed launchy-0.3.3 Successfully installed shotgun-0.2 3 gems installed Installing ri documentation for launchy-0.3.3... Installing RDoc documentation for launchy-0.3.3... |
| ~/samples/railsconf/sinatra/basic-rack
>~/tools/jruby/bin/jruby -J-Djruby.fork.enabled=true -S shotgun [2009-05-04 13:55:46] INFO WEBrick 1.3.1 [2009-05-04 13:55:46] INFO ruby 1.8.6 (2009-03-16) [java] == Shotgun starting Rack::Handler::WEBrick on localhost:9393 [2009-05-04 13:55:46] INFO WEBrick::HTTPServer#start: pid=91089 port=9393 |
| class
BasicRack def call(env) body = if env["PATH_INFO"] == "/foo" "in foo" else "in other" end [ 200, { 'Content-Length' => body.size.to_s, 'Content-Type' => 'text/html', }, [body] ] end end run BasicRack.new |
| class
BasicRackApp def call(env) body = "hello from app" [ 200, { 'Content-Length' => body.size.to_s, 'Content-Type' => 'text/html', }, [body] ] end end class MyMiddleware def initialize(app) @app = app end def call(env) @app.call(env) end end use MyMiddleware run BasicRackApp.new |
| use Rack::CommonLogger |
|
def call(env) status, headers, body = @app.call(env) body.map! { |part| part.upcase} [status, headers, body] end |
| require
'sinatra' |
| ~/samples/railsconf/sinatra/basic-sinatra
>~/tools/jruby/bin/jruby
-rubygems basic-sinatra.rb == Sinatra/0.9.1.1 has taken the stage on 4567 for development with backup from WEBrick [2009-05-04 14:40:14] INFO WEBrick 1.3.1 [2009-05-04 14:40:14] INFO ruby 1.8.6 (2009-03-16) [java] [2009-05-04 14:40:14] INFO WEBrick::HTTPServer#start: pid=91396 port=4567 |
| require
'rubygems' require 'sinatra' not_found do 'hi from other' end get '/foo' do 'hi from foo' end |
| require
'rubygems' require 'sinatra' get '/env' do env.inspect end |
| require
'rubygems' require 'sinatra' get '/' do end post '/' do end put '/' do end delete '/' do end |
| require
'rubygems' require 'sinatra' get '/' do content_type "application/json" { "foo" => "goo" }.to_json end |
| <html> <body> Hello form Sinatra + ERB </body> </html> |
| require
'rubygems' require 'sinatra' get '/' do erb :index end |
| require
'rubygems' require 'sinatra' require 'haml' get '/' do haml :index end |
| %html %body %h1 Hello from HAML |
| require
'rubygems' require 'sinatra' require 'haml' get '/' do erb :index end use_in_file_templates! __END__ @@ index <html> <body> Hello form Sinatra + ERB in file </body> </html> |
| require
'rubygems' require 'sinatra' require 'haml' get '/' do erb :index end get '/foo' do erb :foo end use_in_file_templates! __END__ @@ index <html> <body> Hello form Sinatra + ERB in file </body> </html> @@ foo <h1>FOO!</h1> |
| require
'rubygems' require 'sinatra' require 'haml' helpers do end |
| require
'rubygems' require 'sinatra' require 'haml' module helpers def self.dosomething(arg) end end get '/' do Helpers.dosomething end |
TOTD #81: How to configure "database.yml" to be used with both JRuby and MRI ?
In JRuby-on-Rails
tutorial at Rails
Conf 2009, Nick
Sieger shared a nice little tip on how to configure
"database.yml" to be usable with both JRuby and MRI:
| <% jdbc = defined?(JRUBY_VERSION) ? 'jdbc' : ''
%> development: adapter: <%= jdbc %>mysql encoding: utf8 reconnect: false database: myapp_development pool: 5 username: root password: socket: /tmp/mysql.sock # ... |
Posted by Arun Gupta in General | Comments[0]
|
|
|
|
|
Today's Page Hits: 1714
Total # blog entries: 999
| « November 2009 | ||||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
1 | 2 | 4 | 6 | 7 | ||
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | |||||
| Today | ||||||