Sky
Sky

Reputation: 4853

Rails 3 form validations without a model

I've created a contact form using form_tag and other simple non-model-related rails form helpers. The form just submits an email to the site administrator. Anyway, I'd like to validate the fields on the form, but I'm having trouble finding a Rails-friendly way of doing this.

I found this answer to what seems to be the same question, however the accepted answer didn't seem to present a clear solution for Rails 3 (it seemed more oriented toward Rails 2). Could someone provide a concise example of how to easily do client-side validation of a form not related to a model in Rails 3? Extra points for a strategy that utilizes the default Rails validators.

And let's pretend my form looks something like this:

<%= form_tag "/contact" do %>
  <%= text_field_tag :name %>
  <%= text_field_tag :email %>
  <%= text_area_tag :message %>
  <%= submit_tag "Submit" %>
<% end %>

Upvotes: 1

Views: 1226

Answers (1)

stfcodes
stfcodes

Reputation: 1380

Give active_attr a try. Here's a short audio description.

I personally haven't tried it yet, but was thinking I will in the near future.

Also, in Rails 4, you'll kind of have the same functionality of the gem included: http://blog.plataformatec.com.br/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/. And audio description :-).

Upvotes: 1

Related Questions