Sunday, May 23, 2010

Workshop 5 - Part C

Part C: Screen layouts and forms processing with text fields, check boxes, radio buttons and multiple list controls

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








4. Add a view template - cabs\app\views\vehicle\cabtype.rhtml










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








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

I needed to make a few changes to the example input.html as it had a number of html issues, so that it would render correctly, and also the post value was only going to vehicle and not vehicle/cabtype



































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

class VehicleController< ApplicationController

def cabtype

@data1 = params[:text1]

@data2 = params[:check1]

@data3 = params[:radios1]

@data4 = params[:building1]

end

end



8. Edit the view template cabtype.rhtml

I also needed to make a few adjustments to the cabtype.rhtml as the @data2 element if was not working correctly





















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


Last but not least, there seems to be an issue with the workshop in regards to the input.html not being autogenerated from ruby but instead manually created. This causes an issue with ruby as it has inbuilt security features to ensure we are trying to get past its built in security. This however renders the application example useless as it stops it from working. To get around this problem i needed to comment out a particular piece of code contained in the application_controller.rb file which would turn off this ruby check so that the example would work. I probably wouldn't recommend this as a way forward, but to get this example to work this was the only way i could find.












































No comments:

Post a Comment