Showing posts with label Workshop 6. Show all posts
Showing posts with label Workshop 6. Show all posts

Sunday, July 19, 2009

Workshop 6/7: Application Success

The following screenshots define the application that I developed today after reading RailsSpace and developing as I read:
The home page:

The about page:

The help page:

The login page:

The user hub once logged in:

Choosing to book a taxi:

The user selections from the booking screen. This is where more work would need to be done in a production environment or working application. A booking record would need to be written at this point and the user notified of thir booking number.

If the user selects Boioking History from the hub screen then all booking for the current user should be displayed.

If the user selects the logout option then they get sent here:

The following shows the user registration screen:

Here we see that we have form validation enabled:

This shows a succesfully registered user, has the same effect as a user logging in:

Workshop 6/7: Integrating RailsSpace with OTBS

I have got the RailsSpace application to the point where it should be really easy to integrate what i had done previously with the OTBS.With that in mind
  1. I created a vehicle controller
    ruby script/generate controller Vehicle cabtype bookcab
  2. modified the bookcab.html.erb to look like we did in Workshop 4
  3. Changed the link in the application.html.erb file to point to the vehicle bookcab form


    Unfortunately when you choose the link I get the following error message:

    I would love to continue investigating the issue, but unfortunately I have now developed a visual migraine, and looking at the computer screen is akin to looking at a kalaidescope.
  4. Pregnant pause for 2 hours .....

  5. Well I have my application working. Yee haa! The comment from Karen helped in the end. The error about the unknown route was purely because I had not restarted the server after creating the vehicle controller.
  6. I have managed to integrate the RailsSpace application with the OTBS application we have been developing. See my next post for application details.

Workshop 6/7: Developing RailsSpace

The following are the steps I have taken to develop the RailsSpace application:
  1. ruby script/generate controller Site index about help
  2. Here is where we learn how do undo things.
    ruby script/destroy controller
  3. Change the root mapping in the routes.rb file
    map.connect '', :controller => "site"
  4. Then to ensure that the default routing works we need to remove the public/index.html page.
  5. Modify the pages defined when we created the Site controller (index, about and help)
  6. Modify layouts.
  7. Add navigation and the site looks like:

  8. Add css and the site now looks like

  9. Well now we want to create a user so we need a database. I have create a mysql database called railsspace.
  10. Generate the user model
    ruby script/generate model User
  11. create the user in the database
    rake db:migrate
  12. learn here that we can roll back the database migration by using the command;
    rake db:migrate VERSION=0
  13. Add validation to the user model.
  14. Testing the validation gives the following output
  15. Add magic columns to the model
    ruby script/generate migration AddUserTimestamps
  16. Add user controller to enable us to register users
    ruby script/generate controller User index register
  17. At this point I got a hosting error within APTANA studio that says I couldnt have 2 application using the same host. I have gotten this error before and the only solution I could find was to close and restart APTANA. This worked.
  18. So I now have the following nicely rendered registration page:
  19. Add debugging info so that we can debug easily. Gee I wish I had seen this before. Very nice!!
  20. Continuing on we deal with what happens if a user registers successfully.The following screenshot shows this taking place:
  21. Add the link to the registration page in the application.html.erb file
  22. Add a helper function to reduce ugly code and then review documentation
    rake doc:app
    and then view doc/app/index.html
  23. Clean up the database
    rake db:migrate VERSION=0
    This will clean the database

    rake db:migrate
    This will rebuild the database

  24. I would love to investigate the testing functionality within ROR but due to time constraints I am going to bypass this section. (Here is hoping that this decision doesnt come back to bite me.)
  25. I am now back to where I started the RailsSpace review earlier today. ie I have now created the session
  26. Modify the user_controller so that registered users are automatically logged in.
  27. Change the application.html so that if we are developing we can see what the session variable contains as well. Add some javascript to display individual debug options seperately as required.
  28. Lets add a login template and link the main application screen accordingly.
  29. We can now add a logout page as well and modify the code so that the appropriate menu items appear dependent upon the logged in condition.
  30. Now lets create a protected page
    I added the code "the stupid way" as the book says inside the controller and verified that it worked.
  31. Add nice URL forwarding to protected pages, once user is authorised, by utilising the properties of the request.request.uri
  32. At this point we are all about looking at code refactoring

Workshop 6/7: Reading RailsSpace

Well I think that I made another mistake in developing my application. I didnt read the railsspace text sufficiently. I relied on the learningrails podcats/screencast series to develop the login module. As you will have noticed reading my blog this was in no way successful.

I am currently reading section 6 of RailSpace and it looks like it shows what i should have done to get the login process to work. It is actually debateable at this point as to what i would need to do to get the OTBS to work and utilise the login functionality correctly. It could be that if I implement the session logging capabilities in Section 6 of RailsSpace, that i may actually get a functioning application. But on the other hand, I may find that I am being led up yet another garden path.

In order to investigate whether RailsSpace would in fact revive my application I would be inclined to once again rebuild my OTBS application from the ground up. This goes entirely against the principles espoused by the rails community of DRY or dont repeat yourself (did I actually just break that rule by spelling out the DRY definition?). But considering I am between a rock and a hard place in terms of a functioning application, I feel that this is sctually the best method.

Concurrently with starting with a completely fresh application, I would implement a source code control systems to ensure that I was able to backtrack if and when the need arose.

Well I have just created a new rails application, to see if the logging mechanism within RailsSpace will actually work for me. Following on from the steps is section 6:

  1. Run rake db:sessions:create
  2. This was successful
  3. In config/environment.rb, uncomment the line:config.action_controller.session_store = :active_record_store
  4. Well here was my first problem. There was no such line in the file. So I copied the line from RailsSpace into the file.
  5. Run rake db:migrate
  6. Well this bit worked fine.
  7. Its at this point that I realise that we need to go back to the beginning of the book and actually build an application, because there is currently nothing in this one. So its back to the start of Chapter 2.

Workshop 6/7: Login Headache

You may have read my rant on the developer forum about ROR giving me a headache. Well here is my expanation of my issue. I have followed the learningrails webcast series for developing web applications, and you may notice that the css that I have used in my OTBS comes straight from them. In webcast 10 and 11 they develop or introduce the sessions controller and include the AuthenticatedSystem. My problem arises from the fact that no matter what i seem to do the authentication controller seems to think I am logged in. Below is a screen shot of my application.html.erb file: Unless I have completely got it wrong, the "logged_in?" is not getting changed, and the session is staying live (so to speak), which really makes it impossible to test my application correctly. If the user is not logged in I dont want them to be able to book a cab. Unfortunately, I always seem to be logged in. So to reiterate what I said on the developer forum(on 8th July):
I am definitely starting to loath the whole Ruby on Rails experience. I have been endeavouring to get something as simple as sessions to work. I am either connected or not. Well that all sounds good. Except for the fact that I am connected when I shouldnt be. Following the learningrails screencasts, I add authentication to the application. I add the before_filter to all the relevant controllers. However when I logout, i stay logged in. AAAARRRRGGHHHH!!!!
The thing that has stood out for me with Ruby, that they said ad nauseum on the learningrails webcast series, developing with Ruby is MORE FUN. Well in my experience NOT is actually more the case. It is more infuriating than anything else I have ever had to program. When it works it is good. When it doesnt my only response is AAAARRRRGGHHHH!!!!

Monday, July 6, 2009

Workshop 5/6: More Taxi booking system - followup

Must give thanks to Karen's comment. Even though what she said to do was what I had done, the fact that she commented actually triggered the correct outcome for me.

I have got the BookCab form integrated with my OTBS. In order to do this I had to do the following

  1. Move the bookcab method into the VehicleController
  2. Move the bookcab.html.erb file into the views\vehicle\ directory
  3. Change the form action to form_action ="cabtype" instead of "vehicle/cabtype"
  4. modify my application.html.erb file so that the 'Book Cab' link pointed to the correct controller and action.

On the face of it it looks like the variable scope is confined to the MVC that is of interest. In this case it was the cab booking variables in the bookcab view being transferred to the cabtype view.

My next step now is to introduce a login mechanism and enable passenger information to be collected.

Sunday, July 5, 2009

Workshop 5/6: More Taxi booking system

I have just been having a lot of fun.

I thought I would go back into the Taxi Booking system, to improve the look of the site and to look at adding login functionality. This would involve utilising what we had developed in workshop 4 with the changes in workshop 5.

I also wanted to change how I had dealt with the protect_from_forgery error that we all got in workshop 5. I simply hashed out the line, and so everything worked.

Well the idea started out as a good one. Unfortunately, I managed to break everything, so that nothing worked. I changed the routes file so that there were no recognised routes.

Scratching my head for half an hour ensued, until I realised that I had in actual fact hashed out all the route info in the routing file. So message actually made sense. With that sorted out and the taxi details showing again I decided to press on.

My Online Taxi Booking System now looks like

Unfortunately the information doesn't came across as you can see by the following:

I am beating my head against a brick wall at the moment. Possibly mind gone blank syndrome. I definitely need to get back to RailsSpace, for another installment, which might clear things up a bit. In the meantime, I close this blog post with a screenshot of my pages_controller and file structure

You may notice that the Vehicle Controller is empty. I was getting some routing issues and so just moved the code into the pages controller. I am definitely thinking this was the wrong way to go. But that is where it is at the moment.

Update

Well after posting this blog, I had a slight rethink and put the Cabtype method back into the vehicle controller. The views all seem to work, and the cabtype view does get displayed after submitting the booking form. Alas the variables are not being initialised, so the cabtype view is not displaying the selected information. Any ideas anyone?

Monday, June 29, 2009

Some very helpful Ruby tomes

I have just going through Workshop 6 and the Topic reading: (Hartl)

This made mention of David Hannermeir Hansens 15 minute blog development presentation. http://media.rubyonrails.org/video/rails_take2_with_sound.mov in the introduction. I watched this (i suspect that Craig had recommended this earlier) and wish that I had seen this earlier in the subject.

Having watched the demonstration, I read (Collingbourne)

I now feel that I have a much better grasp of ROR, because of these references. I have gotten back into the first few chapters of (Hartl) and really wish that this had been recommended prior to Workshop 1. It goes through a nice seemingly simple step by step process for setting up rails, and actually specifies requirements. There is a distinct chance that maybe hindsight is playing a part in my thinking, remembering back to the number of lost hours trying to get a working setup.

However, what really got me to put this missive together was a single line in (Hartl, s2.2.1)

In case you ever need to undo the work done by generate, you can use ruby script/destroy controller . That's certainly a lot easier than deleting a bunch of files by hand.
which clarified in my mind where I had been going wrong in my attempts at building the OTBS. i may well have seen this before, but I don't remember seeing this in the same section as talking about generating the controller. But then again, this may well be hindsight in action.


References
Collingbourne, H (2008)"The Little Book of Ruby"
Hartl, M & Prochazka, A, (2008). RailsSpace: Building a Social Networking Website with Ruby on Rails, Pearson Education

Tuesday, June 23, 2009

Workshop 6: Enjoying the Ride: Web framework alternatives, scalability and flexibility

Upon the completion of this workshop, developers or managers should be able to:
  • Discuss and analyse the latest Web framework technologies based upon experiences so far with Ruby on Rails
  • Identify and evaluate challenges and opportunities concerning the use of the latest Web 2.0 technologies and to ‘benchmark’ (compare) other alternatives
  • Discuss and evaluate current Ruby on Rails framework and the alternative emerging technologies.
  • Evaluate and devise scalability, flexibility, capacity planning and performance testing strategies for conducting e-commerce.
  • Deploy Web 2.0 or later technology in their business environments such as the ideas and methods of the ‘RailsSpace’ approach to the OTBS
  • Think critically and analytically when exposed to new technologies.
  • Share your findings with your peers and examine what the other team is doing.
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
Share your success by posting progress comments and links etc to the Developers sub-forum site that has been set up for the Red team.