Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 1.00 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Rendering joined array to display Rails Errors
  2. if @person.errors.blank? && @person.save
  3.   flash[:info] = "Your profile has been successfully updated."
  4.   redirect_to profile_url(@person) and return
  5. else
  6.   if @person.errors.on(:first_name).is_a?(Array)
  7.     @person.errors.on(:first_name).join
  8.   end
  9.   flash[:warning] = "Sorry, there was a problem saving your profile. Please try again."
  10.   render :edit
  11. end
  12.        
  13. %li
  14.         = label(:person, :first_name, "First Name")
  15.         = f.text_field :first_name
  16.         - if @person.errors[:first_name].present?
  17.           %span{:style => "color: red; margin-left: 180px;"}=   @person.errors[:first_name]
  18.        
  19. if @person.errors.present?
  20.   @person.errors.each do |err|
  21.     = err
  22.        
  23. if @person.save
  24.   flash[:info] = "Your profile has been successfully updated."
  25.   redirect_to profile_url(@person)
  26. else
  27.   @person.errors[:first_name] = @person.errors.on(:first_name).to_a.join
  28.   flash[:warning] = "Sorry, there was a problem saving your profile. Please try again."
  29.   render :edit
  30. end