I probably chose a bad example by using something
for which there is magic.
But wait!. There’s more !!!
Suppose that additionally I want to save something else
in the db entry that arises after the webform has been
submitted. (Example: my site will have logged-in users,
and I’d like to save is the “id” of the user who has used
the webform.) Is there a way I can tell RoR to run some
code, after the form has been submitted?
Several. Easiest to start with is filters.
From the docs (at http://api.rubyonrails.org) on the
“Filters enable controllers to run shared pre and post processing code
its actions. These filters can be used to do authentication, caching, or
auditing before the intended action is performed. Or to do localization
output compression after the action has been performed. Filters have
to the request, response, and all the instance variables set by other
filters in the chain or by the action (in the case of after filters).”
If you’re new to the api documentation you’ll find the module doc links
the middle-left frame. The lower-left contains links by method into the
module docs. Poking around in the methods is time well spent.
Don’t worry if the beginning sections are a bit over your head re: OO
concepts and terminology. Skip to the ‘Filter chain ordering’ section.
You’re interested in the before_filter and after_filter methods. Google
‘rails after_filter’ for more, including sample code.