rails validation of presence not failing on nil

Posted by holden on Stack Overflow See other posts from Stack Overflow or by holden
Published on 2010-11-19T14:10:56Z Indexed on 2012/11/21 17:00 UTC
Read the original article Hit count: 287

I want to make sure an attibute exists, but it seems to still slip thru and I'm not sure how better to check for it.

This should work, but doesn't. It's a attr_accessor and not a real attribute if that makes a difference.

validates_presence_of :confirmed, :rooms

{"commit"=>"Make Booking",
 "place_id"=>"the-kosmonaut",
 "authenticity_token"=>"Tkd9bfGqYFfYUv0n/Kqp6psXHjLU7CmX+D4UnCWMiMk=",
 "utf8"=>"✓",
 "booking"=>{"place_id"=>"6933",
 "bookdate"=>"2010-11-22",
 "rooms"=>[{}],
 "no_days"=>"2"}}

Not sure why my form_for returns a blank hash in an array...

<% form_for :booking, :url => place_bookings_path(@place) do |f| %>
<%= f.hidden_field :bookdate, { :value => user_cart.getDate } %>
<%= f.hidden_field :no_days, { :value => user_cart.getDays } %>

<% for room in pricing_table(@place.rooms,@valid_dates) %>

  <%= select_tag("booking[rooms][][#{room.id}]", available_beds(room)) %>

<% end %>
<% end %>

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about validation