I have some standard checks in my model:
validates_presence_of :url_string validates_uniqueness_of :url_string validates_presence_of :stream_source validates_presence_of :width validates_presence_of :height validates_presence_of :name validates_uniqueness_of :name validates_presence_of :customer_name validates_presence_of :iframe_background_color
If I do not fill out one of these fields in my form, I will return to the form as expected, but it is strange that error messages do not appear. I use the following code to display error messages:
<% @camera.errors.full_messages.each do |error| %> <p><%= error %></p> <% end %
I also tried to print the @ camera.errors object, and here is what is shown:
#<ActiveModel::Errors:0x12db19bc @base=#<Camera id: 1, stream_source: "test", width: 640, height: 360, active: true, name: "test", url_string: "CAYD19Vp", customer_name: "test", iframe_background_color: "#FFFFFF", online: true, created_at: "2011-08-30 15:54:16", updated_at: "2011-09-06 15:52:48", audio: true, iframe_text_color: "#FF00FF", iframe_link_color: "#FF0000", notes: "Some notes!", offline_image_file_name: "Cake.jpg", offline_image_content_type: "image/jpeg", offline_image_file_size: 196591, offline_image_updated_at: "2011-09-06 12:12:38", pull_stream_url: "test", bitrate: "300-500", show_branding: false>, @messages={}>
As you can see, the message hash is empty. I tried to set the verification error message manually by following these steps:
validates_presence_of :name, :message => "No name present"
but he also did not populate the message hash.
Controller update action is shown below:
def update @camera = Camera.find(params[:id]) if @camera.update_attributes(params[:camera]) flash[:notice] = "Camera updated" redirect_to nwcadmin_camera_path else redirect_to :action => :edit end end
I am using Ruby version ruby 1.9.2p290 and Rails version 3.1.0.
Any help would be great!
thanks