Wednesday May 16, 2007
Database-enabled Hello World RoR app
UPDATE: Simplified steps for GlassFish V2 are available here and for V3 here.
Follow up from here.In this post I show how a Rails app can talk to database. Here are the steps I followed:
@hello_string = "Hello
World!"'.<%= @hello_string %>'.mysqladmin -u root create
helloworld_development'.Generate',
select 'model', specify the arguments as 'table1',
click 'OK'. This will generate, in NetBeans project, Database
Migrations, migrate, 001_create_table1s.rb.
def self.up
create table :table1s do |t|
t.column :data, :string
end
endRun Rake Target', 'db',
'migrate'. This generates the appropriate database tables.Databases', 'New
Connection ...'.New Driver ...' and specify the location
of mysql-connector-java-5.0.5-bin.jar from the MySQL
Connector/J installation directory.jdbc:mysql://localhost:3306/helloworld_development'.table1s',
select 'Execute Command ...'.insert into table1s values (1, 'Hello
from database')". Run the SQL.hello_string' is initialized
from the database. This is a contrived example but still convey the concept.
Anyway, The code looks like:@hello_string = Table1.find(1).datamysqld --consolesay' and view is 'hello', then
the URL will be 'http://localhost:3000/say/hello'.
The browser will now display 'Hello from database'.In a later post, I'll describe how this same application can be deployed as WAR in GlassFish V2.
Technorati: glassfish rubyonrails ror netbeans jruby ruby
Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
|
Today's Page Hits: 1925
Total # blog entries: 1024
Posted by Arun Gupta's Blog on May 17, 2007 at 07:47 AM PDT #
Posted by Arun Gupta's Blog on May 17, 2007 at 11:34 AM PDT #
Posted by Arun Gupta's Blog on August 07, 2007 at 09:59 AM PDT #
Posted by Arun Gupta's Blog on August 08, 2007 at 09:46 AM PDT #