[Rails] Re: How do you use :message with validation?

Ben Lisbakken
Thu, 20 Jul 2006 10:09:10 -0000

Jean-etienne Durand wrote:
> <%= error_messages_for(''my_model'') %> in your view.
>
> Some css style examples:
> 154 	/* error
> 155 	   ---- */
> 156 	.fieldWithErrors {
> 157 	  padding: 1px;
> 158 	  background-color: red;
> 159 	  display: table;
> 160 	}
> 161 	#errorExplanation {
> 162 	  border: 2px solid red;
> 163 	  padding: 7px;
> 164 	  padding-bottom: 12px;
> 165 	  margin-bottom: 10px;
> 166 	  background-color: #f0f0f0;
> 167 	}
> 168 	#errorExplanation h2 {
> 169 	  text-align: left;
> 170 	  font-weight: bold;
> 171 	  padding: 5px 5px 5px 15px;
> 172 	  margin: -7px;
> 173 	  background-color: #c00;
> 174 	  color: #fff;
> 175 	}
> 176 	#errorExplanation p {
> 177 	  color: #333;
> 178 	  margin-bottom: 0;
> 179 	  padding: 5px;
> 180 	}
> 181 	#errorExplanation ul li {
> 182 	  list-style: square;
> 183 	}

thanks - I''m afraid I wasn''t specific enough.  Wanted the
error message
in my controller, not the view.

here''s how I did it

      @messages = @user.errors.full_messages
      flash[:notice] = @messages[0]
      for i in (1..@messages.length-1)
flash[:notice] += " " + @messages[i]
      end