-
Notifications
You must be signed in to change notification settings - Fork 0
ezform
If you need some form without an active record that is persisted to the database you can call this generator. This generator creates the controllers, helper, views and active model to be able to provide a form without need to persist data but also with the ability to use many rails features like validators etc..
rails generate ez_on_rails:ezform IssueReport title:string description:string workaround_exists:boolean
As you can see this generator takes the same parameter like the rails default scaffold generators. The difference here is that no database migration will be generated.
The controller of the form gets the two actions index and submit. Index is used to access the forms view and submit is the action that is executed to process the given data.
The view is generated the same way like (ezscaff)[https://github.com/D4uS1/ez-on-rails/wiki/ezscaff] generated records are. In the generated helper the render info is used to create the form.
For security purposes the access to the form will be restricted by default. This is accomplished by adding the necessary permissions to the db/seeds.rb file. If you want your form to be accessible for public or other groups consider reading the permission concept and adjust the seeds.
- The active model is located at app/models/.rb
- The model holds accessors for the attributes you passed to the generator
- You are able to use all active model features from rails here, including e.g. validations
- The controller is located at _app/controllers/<your-endpoint.name>controller.rb.
- The controller holds the index and submit actions
- The helper holding the render info to show the form is located in _app/helpers/helper.rb
- The views are located in the app/views/<your-endpoint-name/ directory
- The views are html views written in (slim)[http://slim-lang.com/]
- The view that shows the form is called index.html.slim
- The view that shows the success page if the user submitted the form is called success.html.slim
- The files to provide i18n functionality to your form are located in the config/locales/ directory.
- The specs to test your active model are located in spec/models/<your-endpoint-name_spec.rb
- The specs to test your form are located in spec/requests/<your-endpoint-name_spec.rb
- Appends the needed assignments to the seeds to restrict the access to the form
- Create the routes to view and submit the form and view the success page