Termwork 12

Procedure:

C:\InstantRails-2.0-win\rails_apps>mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1 to server version: 5.0.27-communit

Type 'help;' or '\h' for help.Type '\c' to clear the buffer.

mysql> create database lab15_development;

Query OK, 1 row affected (0.05 sec)

mysql> create database lab15_test;

Query OK, 1 row affected (0.00 sec)

mysql> create database lab15_production;

Query OK, 1 row affected (0.02 sec)

mysql> show databases;

+------+

| Database |

+------+

| information_schema |

| cookbook |

| lab12_development |

| lab12_production |

| lab12_test |

| lab13_development |

| lab13_production |

| lab13_test |

| lab14_development |

| lab14_production |

| lab14_test |

| lab15_development |

| lab15_production |

| lab15_test |

| mysql |

| typo |

| typo_dev |

| typo_test |

+------+

15 rows in set (0.11 sec)

mysql> use lab15_development;

Database changed

mysql> create table books

-> (

-> idint not null auto_increment,

-> namevarchar(80) not null,

-> description text not null,

-> price decimal(8,2) not null,

-> primary key(id)

-> );

Query OK, 0 rows affected (0.08 sec)

mysqldesc books;

+------+------+------+-----+------+------+

| Field | Type | Null | Key | Default | Extra |

+------+------+------+-----+------+------+

| id | int(11) | NO | PRI | NULL | auto_increment |

| name | varchar(80) | NO | | | |

| description | text | NO | | | |

| price | decimal(8,2) | NO | | | |

+------+------+------+-----+------+------+

4 rows in set (0.01 sec)

mysql> exit;

Bye

C:\InstantRails-2.0-win\rails_apps>

C:\InstantRails-2.0-win\rails_apps>rails -d mysql lab15

create

create app/controllers

create app/helpers

create app/models

create app/views/layouts

create config/environments

create config/initializers

create db

create doc

create lib

create lib/tasks

create log

create public/images

create public/javascripts

create public/stylesheets

create script/performance

create script/process

create test/fixtures

create test/functional

create test/integration

create test/mocks/development

create test/mocks/test

create test/unit

create vendor

create vendor/plugins

create tmp/sessions

create tmp/sockets

create tmp/cache

create tmp/pids

create Rakefile

create README

create app/controllers/application.rb

create app/helpers/application_helper.rb

create test/test_helper.rb

create config/database.yml

create config/routes.rb

create public/.htaccess

create config/initializers/inflections.rb

create config/initializers/mime_types.rb

create config/boot.rb

create config/environment.rb

create config/environments/production.rb

create config/environments/development.rb

create config/environments/test.rb

create script/about

create script/console

create script/destroy

create script/generate

create script/performance/benchmarker

create script/performance/profiler

create script/performance/request

create script/process/reaper

create script/process/spawner

create script/process/inspector

create script/runner

create script/server

create script/plugin

create public/dispatch.rb

create public/dispatch.cgi

create public/dispatch.fcgi

create public/404.html

create public/422.html

create public/500.html

create public/index.html

create public/favicon.ico

create public/robots.txt

create public/images/rails.png

create public/javascripts/prototype.js

create public/javascripts/effects.js

create public/javascripts/dragdrop.js

create public/javascripts/controls.js

create public/javascripts/application.js

create doc/README_FOR_APP

create log/server.log

create log/production.log

create log/development.log

create log/test.log

C:\InstantRails-2.0-win\rails_apps>cd lab15

C:\InstantRails-2.0-win\rails_apps\lab15>ruby script/generate scaffold Book name

:stringdescription:textprice:float

exists app/models/

exists app/controllers/

exists app/helpers/

create app/views/books

exists app/views/layouts/

exists test/functional/

exists test/unit/

create app/views/books/index.html.erb

create app/views/books/show.html.erb

create app/views/books/new.html.erb

create app/views/books/edit.html.erb

create app/views/layouts/books.html.erb

create public/stylesheets/scaffold.css

dependency model

exists app/models/

exists test/unit/

exists test/fixtures/

create app/models/book.rb

create test/unit/book_test.rb

create test/fixtures/books.yml

create db/migrate

create db/migrate/001_create_books.rb

create app/controllers/books_controller.rb

create test/functional/books_controller_test.rb

create app/helpers/books_helper.rb

route map.resources :books

C:\InstantRails-2.0-win\rails_apps\lab15>ruby script/server

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)

=> Rails application starting on

=> Call with -d to detach

=> Ctrl-C to shutdown server

** Starting Mongrel listening at 0.0.0.0:3000

** Starting Rails with development environment...

** Rails loaded.

** Loading any Rails specific GemPlugins

** Signals ready. INT => stop (no restart).

** Mongrel 1.1.2 available at 0.0.0.0:3000

** Use CTRL-C to stop

.

*****note don’t close cmd*****

**** open browser and type:

Click on new book

*** After u add the book it shows the following message***

Book was successfully created.



******************UPTILL THIS IS A FIRST PART OF THE PROGRAM************************

Create 2 html files… & save on desktop & later v can store in that folder

1.welcome.rhtml

2.result.rhtml

While saving give d name in double quotes

**************** ”welcome.rhtml” ***********************

html

title</title>

body

<p> Total number of books=<%=@num_books%

</p>

<form action="result">

Enter the searching element:

<input type="text" name="sid"/>

<input type="submit" value="Search"/>

</form>

</body>

</html>

**************** “result.rhtml” ***********************

html

title</title>

body

<p> Entered book id is <%= @bookid %> </p>

form

<table border=1>

tr

thBook id</th

thBook name</th

thDetails</th

thprice</th

</tr

<% @bookz.eachdo |bk|

@id=bk.id

@name=bk.name

@descp=bk.description

@price=bk.price %>

tr

<td> <%= @id %> </td>

<td> <%= @name %> </td>

<td> <%= @descp %> </td>

<td> <%= @price %> </td>

</tr

<% end %>

</table>

</form>

</body>

</html>

****open cmd type ctrl-c to exit from mysql n type the following code************

C:\InstantRails-2.0-win\rails_apps\lab14>ruby script/generate controller main

exists app/controllers/

exists app/helpers/

create app/views/main

exists test/functional/

create app/controllers/main_controller.rb

create test/functional/main_controller_test.rb

create app/helpers/main_helper.rb

**********open the main controller.rb in controller folder & type the following code**********

classMainControllerApplicationController

def welcome

@num_books=Book.count

end

def result

@bookid=params[:sid]

@bookz=Book.find(:all,:conditions=>["name=?",@bookid])\par

end

end

******copy those 2 html files in d following folder**************

C:\InstantRails-2.0-win\rails_apps\lab14\app\views\main

******start server*******

Open browser & type :

Now search for the book