You are on page 1of 7
Build a Rails application to aecept book information viz. Accession number, title, authors, edition and publisher from a web page and store the information in a database and to search for a book with the title specified by the user and to display the search results with proper headings. Steps (o write the program ‘Run all 4 servers ie, Apache Mysql Filezila Mercury Now,open InstantRails-2.0-win from e:drive_ie C:\lnstantRails-2,0-win ‘Then click on I(redcolor) folder,then below window will be op eee ei 21/05 14.2048 Instant Rais: Severs sling 21/05 1420-49 Apache : Apache por (60s used by ™(htpd exe)! 2105 14.20 49MySq Corfigution fie changed 21/08 1420.43 Apache : Configuration fle changed | 21705 15.38.41 MySa : Unerpeced end of MS! Now,click on I (black color near Apache )-> select rails applications > console dow ,a command prompt (is called ruby console window) sereen will opened. oR ifthe I folder is not opened then goto to the toolbar lefiside down (for system) then select rails applications > ruby console window a command prompt (is called ruby console window) sereen will opened... DEPARTMENT OF MCA Iv SEMESTER Then type these commands in that console window as-(note: press Enter after each statement) mysql -U root create database lab14_development; create database labl4_test; create database lab14_production; use labl4_development; create table books (id int not null auto_increment, name varchar(80) not null, description text not null, price decimal(8, 2) not null, primary key(id) ys Afier this Press etrl-e rails -d mysql labl4 (vait until it completes its processes and cursor comes out) ed labld Now,goto C:MlnstantRails-2.0-win\mysgNbim and copy libmySQL.alt fle and paste it in WINDOWS\system32, if the libmySOL.dll file exists replace or delete or if you Couldnot replace or paste or delete stop all the server and paste it. Again goto command prompt (ruby console window) and type as ruby seript/generate seaffold book name:string deseription:text price float {vai until it eompletes its processes and cursor comes out) DEPARTMENT OF MCA 2 IV SEMESTER Goto browser and type in the URL as http:/flocalhost:3000/books now you can insert books description price. Click on NEW BOOK er the fields DEPARTMENT OF MCA Iv SEMESTER again press etrlte in command prompt(ie. ruby console window) and type ruby script/generate controller main (vait until it completes its processes and cursor comes out) Now,this file will generate as main_controtler.rb in CMnstantRails-2.0 win\rails_apps\lab14\app\controllers Now, open the file main_controller.rb and delete the conents inside the file and type this below code and save it in C:\lnstantRails-2.0 win\rails_apps\lab1 4\app\controllers.(in the same folder) main controller.rh class MainController < ApplicationController def welcome @num_books = Book.count end def result ‘@bookid = params{:sid] DEPARTMENT OF MCA, IV SEMESTER call, :conditions => "id = #{@bookid}") Now.open <-2.0-win\vails apps\labld\app\views\main type and save 2 these files. me.rhtml “atitle> Welcome template for books “

Total number of books = <%= “

‘Enter Searching, Element: @unum_books %>

id" > cctitle> Weleome template for books p> Entered book id is <%= @bookid o>

rye Book Id- <% @bookz.cach do |bk| @id = bkid @name = bk.name (@descp = bk.description G@price = bk.price %>
Book Name Details Price
<%= @id %o> @name %> aid>-<%= @desep %> <%= @price ¥or <% end %6> ‘form> abe ear DEPARTMENT OF MCA Iv SEMESTER, Again goto prompt (ie ruby console window) and type as ruby scriptiserver (wait until server starts) Outpu Goto browser and type as http:/Mocalhost:3000/main/welcome DEPARTMENT OF MCA IV SEMESTER IV SEMESTER DEPARTMENT OF MCA

You might also like