5/15/2009

Workshop 6 -part 3

C. Set up a session in OTBS.
C1. Add session-check function in OTBS with following code. (See figure 1 to 4.)
If Session[:uid] is true, the system will display the corresponding page info;
If Session[:uid] is false, the system will request user to login.


Figure 1. Passenger's index.rhtml page

Figure 2. Passenger's new.rhtml page.

Figure 3. Passenger's show.rhtml page

Figure 4. Passenger's edit.rhtml page.

C2. Check the session of OTBS.

i.) If you directly access the passenger's index/new/edit page, it will requests user to login. (see video 1.)

Workshop 6 -part 2

To D0 - part2.
B. Create login page
B1. Create a controller named checkauth for handling some events, for example, logout, session timeout, logged-in redirection(see figure 1.)


Figure 1.
B2. Edit the checkauth controller with the following code (see figure 2.)
i.) pass_login method is used when the user login information has been verified.
ii.) logout method is used when the user logs out the system.
iii.) check_auth is used when the session is invaild.


Figure 2.


B3. Create a method name login in the user controller with following code. (see figure 3.)
The login method mainly is doing:
i.) Collect value of the variable named "login" and "password".
ii.)Check the user name and password whether is vaild, if it is correct, redirect to passengers' index page, if it is incorrect, prompt out an error message.


Figure 3.

B4. Create a user view named register.rhtml with following code. (see figure 4.)

Figure 4.


B5. Restart the TaxiApp project and navigate to login page. (see figure 5.)


Figure 5.

B6. Test login page

i.) Input a wrong login info. (see figure 6.)

Figure 6.


ii.) Input a correct login information. (see figure 7.)

Figure 7.

iii.) Click the link named "Register here". (see figure 8.)


Figure 8.

5/13/2009

Workshop 6-part 1

To do -Part 1

Developers may continue to build upon work with the OTBS using the topic reading to help with user registration and advanced login features from Hartl et al (2008).
  • generate a controller and an action by adding a method(s) to a controller.
  • create a view template for each action and to link to actions from views.
  • use AJAX to improve the user experience.

A. OTBS Registration.
A1. Create a model named user. (See figure 1).

Figure 1.

A2. Edit the file named 002_create_users file for auto generating table by rake migrate (see figure 2.)

Figure 2.

A3. Generate the user table (See figure 3.)

Figure 3.


A4. Create controller name user. (See figure 4.)

Figure 4.

A5. Edit the user controller (See figure 5), use AJAX methods- flash[:info] to show the registration result.
Figure 5.

A6. Add validation in user model (See figure 6.)

Figure 6.

A7. Create a view page named register.rhtml with following code. (See figure 7.)

Use AJAX method - "form_tag(:action => 'register') do" and "submit_tag" for performing the form subumition.

Figure 7.

A8. Restart the taxiapp project and use brower to navigate at http://localhost:3000/user/register (See figure 8.)

Figure 8.

A9. Test the registration page.

a.) Input a null value.


b.) Complete the registration form and click Register button.

c.) Input the created account in the login field..it returns error because that user has already created..

A10. Use MYSQL query browser to check the user named wilson whether is created.

Yes, the account named wilson and his information has already stored in the database.

A11. Add the link which is used to go back to the login page.

5/11/2009

Workshop 5-part 3

To Do - Part3


1. Create a new application called cabs in the same projects directory to demonstrate the use of an active view.

> rails cabs
> cd cabs


2. Create a controller called Vehicle in cabs\app\controllers
cabs> ruby script/generate controller Vehicle

3. Add an action to vehicle_controller.rb as the method called cabtype


4. Add a view template - cabs\app\views\vehicle\cabtype.rhtml
We will edit this view in later steps but you may like to add your own test HTML code to the view at this stage.


5. Save the view and restart the Web server and navigate to http://localhost:3000/vehicle/cabtype


6. Create a file in the public directory - \cabs\public called input.html



7. Edit the vehicle_controller.rb here is a start. The data in each form element in the Rails application can be accessed via its name and a hash called params



8. Edit the view template cabtype.rhtml


9. Start the Web server and go to the opening page of this application at http://localhost:3000/input.html



10. Submit the forms data. What do you find?
a.) Fill in all information and click submit button, like the below figure:


b.) Form data will send to "/vehical/cabtype" by post method and the result is listed as below:


c.) Fill in information but unclick the Yes box and click submit button, and the result is listed as below:

11. Report your progress or findings in your Developers Blog.


Firstly, there are several errors are prompted when we follow the procedure in workshop5. I need spend 3 hours to debug the source code, in details, please refer to my figure.

Secondly, learning from Tutorialspoint(2009), the directory under ruby's project named public which like the public directory for a web server, this directory has web files that don't change, such a s JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). This should be set as the DOCUMENT_ROOT of my web server.

Thirdly, form data of input.html are stored in the methods named cabtype of vehicle controller , and cabtype.rhtml uses pass-by-reference to gather those data from cabtype methods.

References:
Tutorialspoint(2009). "Ruby on Rails 2.1.x - Directory Structure". Received 12th May, 2009 from URL - http://www.tutorialspoint.com/ruby-on-rails-2.1/rails-directory-structure.htm

Workshop 5-part 2

To Do - Part2


1. Create a new application called scenery in the same projects directory to demonstrate the use of an active view.

> rails scenery
> cd scenery




2. Create a controller called Demo in scenery\app\controllers
scenery> ruby script/generate controller Demo



3. Add an action to demo_controller.rb as the method called rubycobe


4. Add a view template - scenery\app\views\demo\rubycode.rhtml
We will edit this view in later steps but you may like to add your own test HTML code to the view at this stage.



5. Save and restart the Web server and navigate to http://localhost:3000/demo/rubycode


6. Use the Time.now example to pass data from an action to a view.



7. Modify and save the rubycode action with a value for the time instance variable in the DemoController class in app\controllers\demo_controller.rb




8. Then modify and save the corresponding view template in \app\views\demo\rubycode.rhtml by adding a call by reference to the action’s instance variable:




9. Restart the Web server and navigate the browser to http://localhost:3000/demo/rubycode

Data has been passed from the action to the view as it is done with SQL requests. The instance variables of a Ruby class are available to view templates by referencing the action’s instance variables by name in the view .rhtml template.








Workshop 5-part 1

To Do - PART A

1. Create the Rails application framework in the projects folder: C:\InstantRails\...\projects\>rails animals

2. Running the application on localhost:3000 using the WeBrick ruby server (or Mongrel as alternative) and access via Web browser at http://localhost:3000/

3. Create the controller to make the application do an action. This is under the controller-action/model-view structure.

Stop the WEBrick server each time you edit Ruby classes and then re-start or refresh the views you are testing. Use the Ruby command below:

>ruby script/generate controller Mammal


4. Test the controller by starting the WEBrick server and navaigatibng the browser to http://localhost:3000/mammal Note how the controller name is appended to the end of the URL and that no action resulted because there are no controller methods.

5. Create an action by editing and saving the mammal_controller.rb class in projects\animals\app\controllers using your text editor to add the method below:


6. Start the WEBrick server and browse at http://localhost:3000/mammals/breathe where you will get a “missing template” message since it is missing a view for the breathe method.

Rails is trying to connect the breathe method action of the mammal controller to a view, by using the action’s name – breathe. This view template is created as breathe.rhtml and stored in the \projects\animals\views\mammal directory.




7. Create and save a view in that directory by using a text editor to create a view called breathe.rhtml


8. Try Ruby code and HTML in the action view by using the <%....%>wrapper around the inserted Ruby code. Here are some snippets to try from workshop 4: