Can I use ActiveRecord-like form validation when using form_tag and not form_form (hence a for not bound to a model)? How?
You can't have validations with form_tag as your form is not bound to a model.
But the good part is that with Rails 3 and ActiveModel you can create models that are not bound to your database. So you can create "virtual" models with validations for search forms, contact forms, etc.
See : https://github.com/novagile/basic_active_model
As form_tag does not bound to any models, so you have to validate the data and write code for displaying the errors by yourself.
Or you could try to create non-database-backend models with validations and use form_for instead.
This works well for me in Rails 3.0.9:
<%= form_tag("/events", :id => "new_event") do %>
<%= error_messages_for @event %>
<%= submit_tag "Submit" %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With