I have this validation in my model: validates :name, :rate, :presence => true, :numericality => true In my Controller#create method I have: if @timesheet.create_command_officer(params[:command_officer]) format.html { redirect_to(edit_incident_timesheet_path, :notice => ''Command officer was successfully created.'') } else format.html { redirect_to(edit_incident_timesheet_path, :notice => ''Could not save Command Officer.'') } Now when I enter ''aaa'' in the Rate field and submit, the record DOES NOT get saved to the database, but the controller redirects with ''Command officer was successfully created.'' instead of giving me reasons why the record could not be saved. Why doesn''t the model give me errors saying why the record can''t be saved? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 January 2011 17:22, Finne Jager <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have this validation in my model: > > validates :name, :rate, :presence => true, :numericality => true > > In my Controller#create method I have: > > if @timesheet.create_command_officer(params[:command_officer]) > format.html { redirect_to(edit_incident_timesheet_path, :notice > => ''Command officer was successfully created.'') } > else > format.html { redirect_to(edit_incident_timesheet_path, :notice > => ''Could not save Command Officer.'') } > > > Now when I enter ''aaa'' in the Rate field and submit, the record DOES NOT > get saved to the database, but the controller redirects with ''Command > officer was successfully created.'' instead of giving me reasons why the > record could not be saved.Do your tests that check that the validations on CommandOfficer work correctly pass ok? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #972568:> On 5 January 2011 17:22, Finne Jager <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> format.html { redirect_to(edit_incident_timesheet_path, :notice >> => ''Could not save Command Officer.'') } >> >> >> Now when I enter ''aaa'' in the Rate field and submit, the record DOES NOT >> get saved to the database, but the controller redirects with ''Command >> officer was successfully created.'' instead of giving me reasons why the >> record could not be saved. > > Do your tests that check that the validations on CommandOfficer work > correctly pass ok? > > ColinI haven''t learned much about tests yet and haven''t used them so far. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Finne Jager wrote in post #972574: [...]>> Do your tests that check that the validations on CommandOfficer work >> correctly pass ok? >> >> Colin > > I haven''t learned much about tests yet and haven''t used them so far....and now you know why you must -- it''s hard to tell what isn''t working if you don''t have them. Testing is not optional. So...stop writing application code now. Get RSpec and Cucumber, and write a comprehensive test suite for your application. Preferably, do so before writing *one more line* of application code. At a minimum, write tests for the next thing you''re trying to implement -- before you implement it. Do all future development test-first -- that is, write one failing test, watch it fail, and then do the simplest thing to make it pass. Refactor once the test passes -- if you have a comprehensive test suite, you''ll know that the refactoring hasn''t broken anything. This is how reliable software is made. Anything less is just hacking. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.