Tuesday November 18, 2008
TOTD #53: Scaffold in Merb using JRuby/GlassFish
GlassFish
Gem 0.9.0 can be used to run Rails and Merb applications.
Support another Rack-based framework Sinatra is coming up in the near
future. This blog shows how to create a scaffold in Merb and run it
using the
GlassFish gem.

| ~/samples/jruby/merb >~/tools/jruby-1.1.5/bin/jruby -S
merb-gen core --orm activerecord hello Generating with core generator: [ADDED] gems [ADDED] merb.thor [ADDED] .gitignore [ADDED] public/.htaccess [ADDED] doc/rdoc/generators/merb_generator.rb [ADDED] doc/rdoc/generators/template/merb/api_grease.js [ADDED] doc/rdoc/generators/template/merb/index.html.erb [ADDED] doc/rdoc/generators/template/merb/merb.css [ADDED] doc/rdoc/generators/template/merb/merb.rb [ADDED] doc/rdoc/generators/template/merb/merb_doc_styles.css [ADDED] doc/rdoc/generators/template/merb/prototype.js [ADDED] public/favicon.ico [ADDED] public/merb.fcgi [ADDED] public/robots.txt [ADDED] public/images/merb.jpg [ADDED] Rakefile [ADDED] app/controllers/application.rb [ADDED] app/controllers/exceptions.rb [ADDED] app/helpers/global_helpers.rb [ADDED] app/views/exceptions/not_acceptable.html.erb [ADDED] app/views/exceptions/not_found.html.erb [ADDED] autotest/discover.rb [ADDED] autotest/merb.rb [ADDED] autotest/merb_rspec.rb [ADDED] config/init.rb [ADDED] config/rack.rb [ADDED] config/router.rb [ADDED] config/environments/development.rb [ADDED] config/environments/production.rb [ADDED] config/environments/rake.rb [ADDED] config/environments/staging.rb [ADDED] config/environments/test.rb [ADDED] public/javascripts/application.js [ADDED] public/stylesheets/master.css [ADDED] spec [ADDED] app/views/layout/application.html.erb |
| ~/samples/jruby/merb/hello >merb-gen resource Runner
distance:float,minutes:integer Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb Generating with resource generator: Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb [ADDED] spec/models/runner_spec.rb [ADDED] app/models/runner.rb [ADDED] schema/migrations/001_runner_migration.rb [ADDED] spec/requests/runners_spec.rb [ADDED] app/controllers/runners.rb [ADDED] app/views/runners/index.html.erb [ADDED] app/views/runners/show.html.erb [ADDED] app/views/runners/edit.html.erb [ADDED] app/views/runners/new.html.erb [ADDED] app/helpers/runners_helper.rb resources :runners route added to config/router.rb |
| ~/samples/jruby/merb/hello
>rake db:create (in /Users/arungupta/samples/jruby/merb/hello) JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb ~ It took: 0 ~ Loading: Merb::BootLoader::MixinSession ~ It took: 0 ~ Loading: Merb::BootLoader::BeforeAppLoads ~ It took: 0 ~ Loading: Merb::Orms::ActiveRecord::Connect ~ No database.yml file found in /Users/arungupta/samples/jruby/merb/hello/config. ~ A sample file was created called database.yml.sample for you to copy and edit. |
| :development: &defaults :adapter: mysql :database: hello_development :username: root :password: :host: localhost :socket: /tmp/mysql.sock :encoding: utf8 |
| ~/samples/jruby/merb/hello >rake db:create (in /Users/arungupta/samples/jruby/merb/hello) JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb ~ It took: 0 ~ Loading: Merb::BootLoader::MixinSession ~ It took: 0 ~ Loading: Merb::BootLoader::BeforeAppLoads ~ It took: 0 ~ Loading: Merb::Orms::ActiveRecord::Connect ~ Connecting to database... ~ It took: 0 ~ Loading: Merb::BootLoader::LoadClasses ~ It took: 0 ~ Loading: Merb::BootLoader::Router ~ Compiling routes... ~ It took: 0 ~ Loading: Merb::BootLoader::Templates ~ It took: 0 ~ Loading: Merb::BootLoader::MimeTypes ~ It took: 0 ~ Loading: Merb::BootLoader::Cookies ~ It took: 0 ~ Loading: Merb::BootLoader::SetupSession ~ It took: 1 ~ Loading: Merb::BootLoader::SetupStubClasses ~ It took: 0 ~ Loading: Merb::BootLoader::AfterAppLoads ~ It took: 0 ~ Loading: Merb::BootLoader::ChooseAdapter ~ It took: 0 ~ Loading: Merb::BootLoader::RackUpApplication ~ It took: 0 ~ Loading: Merb::BootLoader::ReloadClasses ~ It took: 0 DEPRECATION WARNING: You're using the Ruby-based MySQL library that ships with Rails. This library will be REMOVED FROM RAILS 2.2. Please switch to the offical mysql gem: `gem install mysql` See http://www.rubyonrails.org/deprecation for details. (called from mysql_connection at /Users/arungupta/tools/jruby-1.1.5/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/connection_adapters/mysql_adapter.rb:81) ~ SQL (0.000581) SET NAMES 'utf8' ~ SQL (0.000581) SET SQL_AUTO_IS_NULL=0 ~ SQL (0.000894) CREATE DATABASE `hello_development` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_general_ci` MySQL hello_development database successfully created |
| ~/samples/jruby/merb/hello
>rake db:migrate (in /Users/arungupta/samples/jruby/merb/hello) JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb Loading init file from /Users/arungupta/samples/jruby/merb/hello/config/init.rb Loading /Users/arungupta/samples/jruby/merb/hello/config/environments/development.rb ~ It took: 0 ~ Loading: Merb::BootLoader::MixinSession ~ It took: 0 ~ Loading: Merb::BootLoader::BeforeAppLoads ~ It took: 0 ~ Loading: Merb::Orms::ActiveRecord::Connect ~ Connecting to database... ~ It took: 0 ~ Loading: Merb::BootLoader::LoadClasses ~ It took: 1 ~ Loading: Merb::BootLoader::Router ~ Compiling routes... ~ It took: 0 ~ Loading: Merb::BootLoader::Templates ~ It took: 0 ~ Loading: Merb::BootLoader::MimeTypes ~ It took: 0 ~ Loading: Merb::BootLoader::Cookies ~ It took: 0 ~ Loading: Merb::BootLoader::SetupSession ~ It took: 0 ~ Loading: Merb::BootLoader::SetupStubClasses ~ It took: 0 ~ Loading: Merb::BootLoader::AfterAppLoads ~ It took: 0 ~ Loading: Merb::BootLoader::ChooseAdapter ~ It took: 0 ~ Loading: Merb::BootLoader::RackUpApplication ~ It took: 0 ~ Loading: Merb::BootLoader::ReloadClasses ~ It took: 0 DEPRECATION WARNING: You're using the Ruby-based MySQL library that ships with Rails. This library will be REMOVED FROM RAILS 2.2. Please switch to the offical mysql gem: `gem install mysql` See http://www.rubyonrails.org/deprecation for details. (called from mysql_connection at /Users/arungupta/tools/jruby-1.1.5/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/connection_adapters/mysql_adapter.rb:81) ~ SQL (0.000769) SET NAMES 'utf8' ~ SQL (0.000610) SET SQL_AUTO_IS_NULL=0 ~ SQL (0.001609) SHOW TABLES ~ SQL (0.003952) CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB ~ SQL (0.054355) CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`) ~ SQL (0.001691) SHOW TABLES ~ SQL (0.001643) SELECT version FROM schema_migrations ~ Migrating to RunnerMigration (1) == 1 RunnerMigration: migrating =============================================== -- create_table(:runners) ~ SQL (0.005301) CREATE TABLE `runners` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `distance` float, `minutes` int(11), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB -> 0.0107s == 1 RunnerMigration: migrated (0.0114s) ====================================== ~ SQL (0.014063) INSERT INTO schema_migrations (version) VALUES ('1') ~ SQL (0.003585) SHOW TABLES ~ SQL (0.001324) SELECT version FROM schema_migrations ~ SQL (0.001451) SHOW TABLES ~ SQL (0.017054) SHOW FIELDS FROM `runners` ~ SQL (0.018503) describe `runners` ~ SQL (0.009372) SHOW KEYS FROM `runners` |
| require 'config/dependencies.rb' |
| dependency "merb-assets", "1.0" dependency "merb-helpers", "1.0" |
| resources :runners |
| <h1>Runner controller, index
action</h1> <table> <tr> <th>Distance (in miles)</th> <th>Time (in mins)</th> <th colspan="3">Actions</th> </tr> <% @runners.each do |runner| %> <tr> <td><%=h runner.distance %></td> <td><%=h runner.minutes %></td> <td><%= link_to 'Show', resource(runner) %></td> <td><%= link_to 'Edit', resource(runner, :edit) %></td> <td><%= delete_button(runner, "Delete #{runner.distance}") %></td> </tr> <% end %> </table> <%= link_to 'New', resource(:runners, :new) %> |
| <h1>Runners controller, new
action</h1> <%= form_for(@runner, :action => resource(:runners) ) do %> <p> <%= text_field :distance, :label => "Distance (in miles)" %> </p> <p> <%= text_field :minutes, :label => "Time (in mins)" %> </p> <p> <%= submit "Create" %> </p> <% end =%> <%= link_to 'Back', resource(:runners) %> |
| <h1>Runners controller, show
action</h1> <p>Distance (in miles): <%=h @runner.distance %></p> <p>Time (in mins): <%=h @runner.minutes %></p> <%= link_to 'Back', resource(:runners) %> |
| <h1>Runners controller, edit
action</h1> <%= form_for(@runner, :action => resource(@runner)) do %> <p> <%= text_field :distance, :label => "Distance (in miles)" %> </p> <p> <%= text_field :minutes, :label => "Time (in mins)" %> </p> <p> <%= submit "Update" %> </p> <% end =%> <%= link_to 'Show', resource(@runner) %> | <%= link_to 'Back', resource(:runners) %> |





Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Today's Page Hits: 535
Total # blog entries: 1002
Posted by Arun Gupta's Blog on December 03, 2008 at 09:15 AM PST #
Posted by Arun Gupta's Blog on February 03, 2009 at 05:39 AM PST #
thank u arun. Thanks for information
Posted by sinema izle on March 13, 2009 at 01:31 PM PDT #
Posted by Arun Gupta's Blog on April 28, 2009 at 06:16 AM PDT #
Posted by Arun Gupta's Blog on May 06, 2009 at 05:40 AM PDT #