# q: why is the validation error output

**URL:** <https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318>\
**Category:** rubyonrails-talk\
**Created:** [October 25, 2010, 2:23pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318 "2010-10-25T14:23:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![der\_tom](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@der\_tom](https://discuss.rubyonrails.org/u/der_tom)\
**Post date:** [October 25, 2010, 2:23pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/1 "2010-10-25T14:23:03Z")

</div>

# being sent to the Trace-Window?

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [October 25, 2010, 2:59pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/2 "2010-10-25T14:59:51Z")

</div>

you have to post some of your layout code , but it seems like there is a problem with your login form and is getting submitted when you try to access the page, but to be sure we have to see some of the lay out code and we have to know it the login form can be triggered by JS

---

<div class="post-metadata">

**Author:** ![der\_tom](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@der\_tom](https://discuss.rubyonrails.org/u/der_tom)\
**Post date:** [October 25, 2010, 3:08pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/3 "2010-10-25T15:08:34Z")

</div>

user-controller:

flash[:error] =@user.errors flash[:notice] = “Error SignUp - pls try again - Support has been contacted!”

application.html

\<% if flash[:notice] -%\> \<%= flash[:notice]%\> \<%= flash[:error]%\> \<% end -%\>

#i reduced it to the minimum. the user signup form is just a regular form…

what else can i provide?

thx for ur help!

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [October 25, 2010, 3:17pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/4 "2010-10-25T15:17:32Z")

</div>

> user-controller:
> 
> flash[:error] =@user.errors flash[:notice] = “Error SignUp - pls try again - Support has been contacted!”
> 
> application.html
> 
> \<% if flash[:notice] -%\> \<%= flash[:notice]%\> \<%= flash[:error]%\> \<% end -%\>

first change this mess to this

\<% message.each do |name, msg| %\> \<% = content\_tag :div, msg, :id =\> “flash\_#{name}” %\>

> #i reduced it to the minimum. the user signup form is just a regular form…
> 
> what else can i provide?
> 
> thx for ur help!

now look at this

> flash[:error] =@user.errors

this is what you are seen, so what i want to know is,

1. do you see this when you try to login or just by trying to access the root page?
2. what are you using for authentication?
3. can you post the login form?

---

<div class="post-metadata">

**Author:** ![der\_tom](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@der\_tom](https://discuss.rubyonrails.org/u/der_tom)\
**Post date:** [October 25, 2010, 3:28pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/5 "2010-10-25T15:28:15Z")

</div>

1. 

ActionView::TemplateError (undefined local variable or method `message’ for #ActionView::Base:0xb6080e74) on line #32 of app/views/layouts/application.html.erb: 29: 30: 31: 32: \<% message.each do |name, msg| %\> 33: \<%= content\_tag :div, msg, :id =\> “flash\_#{name}” %\> 34: \<% end %\>

1)the problem occurs after hitting the submit button, meaning after the validation failes 2)old rails app \> restful\_authentication 3)login form is more or less basic functionailty, but quite a few fields. ill stripp it down later.

thx

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [October 25, 2010, 3:31pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/6 "2010-10-25T15:31:57Z")

</div>

> 31:
> 
> 32: \<% message.each do |name, msg| %\> 33: \<%= content\_tag :div, msg, :id =\> “flash\_#{name}” %\> 34: \<% end %\>

sorry i strackted that from a partial it should look like this

\<% flash.each do |name, msg| %\> \<%= content\_tag :div, msg, :id =\> “flash\_#{name}” %\>

---

<div class="post-metadata">

**Author:** ![der\_tom](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@der\_tom](https://discuss.rubyonrails.org/u/der_tom)\
**Post date:** [October 25, 2010, 3:36pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/7 "2010-10-25T15:36:54Z")

</div>

just minimized everything down to: \<% form\_for (@user) do |f| -%\>

\<%= f.error\_messages %\>

Login  
\<%= f.text\_field :login, :class=\>‘input\_signup’ %\>

```
<p><label for="email">Email</label><br/>
<%= f.text_field :email, :class=>'input_signup' %></p>

<p><label for="password">Password</label><br/>
<%= f.password_field :password, :class=>'input_signup' %></p>

<p><label for="password_confirmation">Confirm Password</label><br/>
<%= f.password_field :password_confirmation, :class=>'input_signup' %></p>

```

\<%= submit\_tag 'Sign up' %\>

\<% end -%\>

def create @user = User.new(params[:user]) @user.save!

```
if @user.errors.empty?
    flash[:notice] = "Thanks for signing up! Please check your email to activate your account." 
else
  p @user.errors
  flash[:error] =@user.errors
  flash[:notice] = "Error SignUp - pls try again - Support has been contacted!" 
  redirect_to signup_url
end

```

end

result is still:

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [October 25, 2010, 3:41pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/8 "2010-10-25T15:41:16Z")

</div>

remove the ! from the save , when you add a shebang to a rails method you force and exception, so instead of just outputting the age with is flash message you are making rails raise and exception

change this

@user.save!

to this

@user.save

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [October 25, 2010, 3:42pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/9 "2010-10-25T15:42:04Z")

</div>

fixed a typo, i meant “force an exception”

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [October 25, 2010, 3:42pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/10 "2010-10-25T15:42:56Z")

</div>

another typo on “page” i wrote age

---

<div class="post-metadata">

**Author:** ![der\_tom](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@der\_tom](https://discuss.rubyonrails.org/u/der_tom)\
**Post date:** [October 25, 2010, 3:51pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/11 "2010-10-25T15:51:40Z")

</div>

argh - u got very good eyes. oh man - i was so blind…and not thinking cleary. thank u soo much!!!

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [October 25, 2010, 3:56pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/12 "2010-10-25T15:56:05Z")

</div>

> flash[:error] =@user.errors

I think this will cause an error since you are passing a collection to a hash that takes a string, let the form helper handle this and dont use many flashes with the loop or you will only see the last flash set

---

<div class="post-metadata">

**Author:** ![der\_tom](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@der\_tom](https://discuss.rubyonrails.org/u/der_tom)\
**Post date:** [October 25, 2010, 4:00pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/13 "2010-10-25T16:00:52Z")

</div>

i think u r right. i got rid of the @user.errors, but im getting nothing back right now… let me check.

---

<div class="post-metadata">

**Author:** ![der\_tom](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@der\_tom](https://discuss.rubyonrails.org/u/der_tom)\
**Post date:** [October 25, 2010, 4:08pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/14 "2010-10-25T16:08:13Z")

</div>

now i have this: 1) @user.save if @user.errors.empty? flash[:notice] = “Thanks for signing up! Please check your email to activate your account.” else redirect\_to signup\_url end 2) validation via model are al set

1. 

* * *
\<% flash.each do |key, msg| %\> \<%= content\_tag :div, msg, :class =\> "flash", :id =\> key %\> \<% content\_tag :script, :type =\> "text/javascript" do %\> $('\<%= key %\>').style.display = 'none'; new Effect.Appear('\<%= key %\>', {duration: 3}); \<% end %\>

\<% content\_tag :script, :type =\> “text/javascript” do %\> setTimeout(“new Effect.Fade(‘\<%= key %\>’);”, 10000); \<% end %\> \<% end %\>

* * *
\<%= yield :layout %\>

but the only thing i see is this:

'Input

literally, the string “'Input” is being displayed between the hr tags… im confused

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [October 25, 2010, 4:19pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/15 "2010-10-25T16:19:01Z")

</div>

try this please

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [October 25, 2010, 4:21pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/16 "2010-10-25T16:21:56Z")

</div>

for some reason i forgot this is ERB 😛 so this $(‘\<%= key %\>’) does makes sense, but still the output is not what you expect since you will be getting flash\_error, flash\_notice and such and not just error and notice which is the key

---

<div class="post-metadata">

**Author:** ![der\_tom](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@der\_tom](https://discuss.rubyonrails.org/u/der_tom)\
**Post date:** [October 25, 2010, 4:23pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/17 "2010-10-25T16:23:41Z")

</div>

ok, i’ve placed ur snippet in:

* * *
\<% flash.each do |name, msg| %\> \<%= content\_tag :div, msg, :id =\> "flash\_#{name}" %\> \<% end -%\>
* * *
\<%= yield :layout %\>

---

<div class="post-metadata">

**Author:** ![der\_tom](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@der\_tom](https://discuss.rubyonrails.org/u/der_tom)\
**Post date:** [October 25, 2010, 4:25pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/18 "2010-10-25T16:25:39Z")

</div>

> > try this please
> > 
> > > * * *
> > > \<% flash.each do |key, msg| %\>
> > > 
> > > \<%= content\_tag :div, msg, :class =\> “flash”, :id =\> key %\>

> > > \<% content\_tag :script, :type =\> “text/javascript” do %\>

> > > $(‘\<%= key %\>’).style.display = ‘none’; \<=== this makes no sense the selector never sees anything with \<% %\> since this never
> > > 
> > > ```
> > > new Effect.Appear('<%= key %>', {duration: 3}); gets to the browser also the content tag generates this flash_error, flash_notice, etc
> > > 
> > > ```
> > > 
> > > \<% end %\>
> > > 
> > > \<% content\_tag :script, :type =\> “text/javascript” do %\>

> > > setTimeout(“new Effect.Fade(‘\<%= key %\>’);”, 10000); \<=== again try to select something with \<% %\>
> > > 
> > > \<% end %\>
> > > 
> > > \<% end %\>
> > > 
> > > \<%= yield :layout %\>

> 

> for some reason i forgot this is ERB 😛 so this $(‘\<%= key %\>’) does makes sense, but still the output is not what you expect since you will be getting flash\_error, flash\_notice and such and not just error and notice which is the key

thats ok, i would b happy to see anything 😉

---

<div class="post-metadata">

**Author:** ![radhames\_brito](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@radhames\_brito](https://discuss.rubyonrails.org/u/radhames_brito)\
**Post date:** [October 25, 2010, 4:31pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/19 "2010-10-25T16:31:07Z")

</div>

😕 i didnt notice when you changed the original code…

you see this “input” when validation fails or always?

---

<div class="post-metadata">

**Author:** ![der\_tom](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@der\_tom](https://discuss.rubyonrails.org/u/der_tom)\
**Post date:** [October 25, 2010, 4:34pm UTC](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318/20 "2010-10-25T16:34:43Z")

</div>

i test only with wrong data entered

[Next page](https://discuss.rubyonrails.org/t/q-why-is-the-validation-error-output/55318.md?page=2)
