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


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


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
沒有留言:
發佈留言