Part A
1. Create the Rails application framework in the projects folder:

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.


Result from browser

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

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.

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

Result from browser

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:

Result from browser

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

2. Create a controller called Demo in scenery\app\controllers

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


4. Add a view template - scenery\app\views\demo\rubycode.rhtml


Result at browser

8. Then modify and save the corresponding view template

9. Restart the Web server and navigate the browser

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

2. Create a controller called Vehicle in cabs\app\controllers

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

View result

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

Result

10. Submit form data. What do you find?
I found error in the program. The if statement can not progress with the (=) equal to symbol when using boolean type of variable.
After fix the webpage and link. The information pass from webpage and to the controller vehicle_controller.rb and to the result page - cabtype.rhtml for output.
11. Report your progress or findings in your Developers Blog.
The select list use array. It is because the selection from user is the index value but not the text itself. So, the array is used to collect the text back from the index value.
No comments:
Post a Comment