I have an HTML form in Rails like
<form name="input" action="jump">
Title: <input type="text" name="title">
<input type="button" value="Submit">
</form>
I want title to be a required field (i.e. the user cannot leave it blank), and I’d like to verify that in the Rails jump controller. Note that title is not a field in the model; it’s just a form field that’s going to be processed within the controller.
How can I do the verification, and display the error to the user elegantly?
You can use active model to handle things:
class SomeModel << ActiveModel
end
The benefits for this is that you can throw validation and handling of displaying errors on to Rails.
The other way is to do it handling things purely on the controller side:
Tis a less than elegant approach however. If you go this route, I would suggest creating a ruby object to at least moving logic out of the controller.