Class SmerfFormsController
In: app/controllers/smerf_forms_controller.rb
Parent: ApplicationController

This controller contains methods that displays the smerf form, allows the user to answer or edit responses on the form. The controller has been developed using REST and responds to the following requests:

  • GET /smerf_forms/smerf_form_file_name - displays specified smerf form
  • POST /smerf_forms - creates a new record to save responses
  • PUT /smerf_form/1 - updates existing record with responses

Methods

create   show   update  

Public Instance methods

POST /smerf_forms

This method creates a new smerfs form record for the user that contains the users responses to the form. Once the record is saved a message to inform the user is added to flash[:notice] and displayed on the form. The form is redisplayed allowing the user to edit there responses to the questions on the form.

GET /smerf_forms/smerf_form_file_name

where smerf_form_file_name = the name of the smerf form definition file to load and process

This method displays the specified form using the name of the smerf form definition file to identify which form to display. If this is the first time the form is being displayed the form definition file will be read, processed and the results stored in the survay DB table. Subsequently the form will be retrieved directly from the DB.

If the form definition file is modified then the form data in the DB will be rebuilt from the form definition file. Smerf form definition files are stored in the /smerf directory.

To create a link to display a form you can use the Standard REST Path method used for the show action passing the name of the form definition file as a parameter, for example

  link_to('Complete Test Smerf Form', smerf_url('testsmerf'))  # Here is an example link that will display the <em>testsmerf</em> form

PUT /smerf/1

This method will update an existing smerf form record for the user with the updated responses to the question on the form. Once the record is saved a message to inform the user is added to flash[:notice] and displayed on the form. The form is redisplayed allowing the user to further edit there responses to the questions.

[Validate]