The main goal: Allow plugins, gems to add additional form fields to predefined forms.
For example, application has a devise login form:
<%= form_for(resource, :as => resource_name, ...) do |f| %>
<%= devise_error_messages! %>
...
<% end %>
Marketing department wants to start a campaign for the next 2 days (ex: register with a promo code and get X bonus points). So we need to add an additional promo code
field to ALL our registration forms.
Is there a way to add an extra field to the form from my rails-plugin/railtie, and define a on_submit
callback method (to take action on my additional field data)?
Benefits:
- it allows removing the functionality in 2 days or a week simply by removing it from gem file
- guarantee that core site's functionality is not broken, it simply falls back to the original functionality
- guarantee that a developer has not left any code somewhere in the main app
- plugin/railtie takes care of the saving/updating data that belongs to it
Looked at ActionView code, and it seems there is no built in way of doing it. What are your thoughts?
NOTE: Drupal's form_alter
hooks are a great example.