didilin
didilin

Reputation: 41

Form_tag validation in rails 3

I'm newbie in rails and in forum. I'm developing my first ror 3 application and I have a problem with a form.

With a form_for the validation works correctly but with a form_tag i don't know how is possible to do the validation. My code is the next :

<%=form_tag(result_path, :method => "post") do  %> 
    Party: <%= text_field :event,:name %><br/>
    Where: <%= text_field :event,:where %><br/>
    When: <%= text_field :event,:when %><br/>

In my controller I get parameters with :

@event = Event.new(params[:event])

and all works correctly but , how can i do the validations?

thanks a lot

Upvotes: 2

Views: 2116

Answers (3)

socjopata
socjopata

Reputation: 5095

You do your validations in a model. All you need to do is a bit of docs reading :)

http://guides.rubyonrails.org/v3.2.13/active_record_validations_callbacks.html

Upvotes: 1

danivalentin
danivalentin

Reputation: 1687

When you use a form_tag, you have no models associated to it. You will have to code the validation by yourself or create a model that is not bound to your db.

Upvotes: 1

Simpleton
Simpleton

Reputation: 6415

In your events model you'll have to add your validations so:

class Event < ActiveRecord::Base
  .
  .
  validates_presence_of :Party #etc
end

Upvotes: 0

Related Questions