Wp Manual 12

10
Web programming lab Prepared by : Badrinath K Dept of ISE, SJCIT Page 1 12. Build a Rails application to accept 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. In windows XP only : Save InstantRails-2.0-win to C drive and extract it. Create shortcut on desktop for “InstantRails-2.0-win logo” Starting Instant Rails To start Instant Rails, double-click the Instant Rails icon that you put on the desktop. When you first start Instant Rails, it will ask you to confirm that it is OK to regenerate the configuration files. Click on OK. It will now attempt to start both the Apache web server and the MySQL server. You may get a query from your firewall software asking you to confirm you want these to be accessible. It should now show a new window. Two traffic-lights at the top of the window should indicate that it has started the Apache web server and the MySQL server.

description

small and simple programs

Transcript of Wp Manual 12

  • Web programming lab Prepared by : Badrinath K

    Dept of ISE, SJCIT Page 1

    12. Build a Rails application to accept 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.

    In windows XP only :

    Save InstantRails-2.0-win to C drive and extract it.

    Create shortcut on desktop for InstantRails-2.0-win logo

    Starting Instant Rails

    To start Instant Rails, double-click the Instant Rails icon that you put on the desktop. When you

    first start Instant Rails, it will ask you to confirm that it is OK to regenerate the configuration

    files. Click on OK. It will now attempt to start both the Apache web server and the MySQL

    server. You may get a query from your firewall software asking you to confirm you want these to

    be accessible.

    It should now show a new window. Two traffic-lights at the top of the window should indicate

    that it has started the Apache web server and the MySQL server.

  • Web programming lab Prepared by : Badrinath K

    Dept of ISE, SJCIT Page 2

    If you click on the Apache/MySQL buttons, you will get a menu enabling you to start/restart

    these servers.

    To the left of the Apache button, there is another button that has the Instant Rails logo. Clicking

    this button reveals a drop-down menu with the following options:

    Help Log Files Configure Rails Applications Restart Servers Stop Servers and Exit

  • Web programming lab Prepared by : Badrinath K

    Dept of ISE, SJCIT Page 3

    Following will open :

  • Web programming lab Prepared by : Badrinath K

    Dept of ISE, SJCIT Page 4

    Start typing the following in rails prompt :

    rails d mysql lab12

    cd lab12

    mysql u root

    create database lab12_development;

    create database lab12_test;

    create database lab12_production;

    use lab12_development;

    create table books (id int not null auto_increment, accession_num int not null, title vachar(80)

    not null, author varchar(80) not null, edition int not null, publisher varchar(80) not null,

    primary key(id));

    mysql> exit

    ruby script/generate scaffold Book accession_num:int title:string author:string edition:int

    publisher:string;

    START SERVER :

    ruby script/server

    URL

    http://localhost:3000/books

    You can now access your web application by using a browser to visit:

    http://localhost:3000/

  • Web programming lab Prepared by : Badrinath K

    Dept of ISE, SJCIT Page 5

    Type table name: localhost:3000/books

    Click New book Link:

  • Web programming lab Prepared by : Badrinath K

    Dept of ISE, SJCIT Page 6

  • Web programming lab Prepared by : Badrinath K

    Dept of ISE, SJCIT Page 7

  • Web programming lab Prepared by : Badrinath K

    Dept of ISE, SJCIT Page 8

    In rails prompt press ctrl+c server will stop

    Type following command in rails prompt

    ruby script/generate controller main

    Use the following path to have the program file

    C:\Rails\rails_apps\lab12\app\controllers\main_controller.rb

    class MainController < ApplicationController

    def welcome

    @num_books=Book.count

    end

    def result

    @title=params[:title]

    @bookz=Book.find(:all, :conditions=>"title=#{@title}")

    end

    end

    Use the following path to save the program file

    C:\Rails\rails_apps\lab12\app\views\main

    result.rhtml

    welcome template for books

    entered book title is:

    Accession number

    Title

    Author

    Edition

    Publisher

  • Web programming lab Prepared by : Badrinath K

    Dept of ISE, SJCIT Page 9

    Welcome.rhtml

    welcome template for books

    total number of books=

    enter searching book tittle :

    Save as type : all files

    Encoding : utf-8

  • Web programming lab Prepared by : Badrinath K

    Dept of ISE, SJCIT Page 10