# Dislpaying validation errors from one one model to view of another.

**URL:** <https://discuss.rubyonrails.org/t/dislpaying-validation-errors-from-one-one-model-to-view-of-another/65965>\
**Category:** rubyonrails-talk\
**Created:** [December 18, 2012, 4:30am UTC](https://discuss.rubyonrails.org/t/dislpaying-validation-errors-from-one-one-model-to-view-of-another/65965 "2012-12-18T04:30:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumit\_Srivastava](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@Sumit\_Srivastava](https://discuss.rubyonrails.org/u/Sumit_Srivastava)\
**Post date:** [December 18, 2012, 4:30am UTC](https://discuss.rubyonrails.org/t/dislpaying-validation-errors-from-one-one-model-to-view-of-another/65965/1 "2012-12-18T04:30:08Z")

</div>

Hi,

I have a model,

class UserComment belongs\_to :user validates :player\_id, :presence =\> true validates :comment, :uniqueness =\> { :scope =\> :player\_id}

partial “comments” from User. = simple\_form\_for @user, :html =\> {:class =\> ‘comment-form’}, :remote =\> true do |f| %fieldset = f.fields\_for :user\_comments do |uac| = uac.input :comment, :as =\> :text, :input\_html =\> {:rows =\> 5, :width =\> 5} .comment-action = uac.button :submit, :value =\> ‘Comment’, :class =\> ‘btn’

When I click on submit button and if the validation receives any error it does not display it on the view. I am not sure where the problem is.

---

<div class="post-metadata">

**Author:** ![AdofEssex](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@AdofEssex](https://discuss.rubyonrails.org/u/AdofEssex)\
**Post date:** [December 18, 2012, 9:24am UTC](https://discuss.rubyonrails.org/t/dislpaying-validation-errors-from-one-one-model-to-view-of-another/65965/2 "2012-12-18T09:24:16Z")

</div>

It looks like you’re not outputting your errors on your view.

If you go to your terminal/command line and try the following:

type ‘rails c’ to enter the rails console. Here we go do a quick bit of testing to see if the errors are being captured.

type ‘user = User.new’, this’ll output a new User object.

type ‘user.errors’ If it returns Nil then you have a different problem otherwise it’s a case of just displaying your errors.

In your view you could do something like…

\<% if @user.errors %\>

There was an error, please see below.

\<% @user.errors.full\_messages.each do | msg | %\>

- \<%= msg %\>

\<% end %\>

\<% end %\>

I hope that helps.

---

<div class="post-metadata">

**Author:** ![Sumit\_Srivastava](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@Sumit\_Srivastava](https://discuss.rubyonrails.org/u/Sumit_Srivastava)\
**Post date:** [December 18, 2012, 9:28am UTC](https://discuss.rubyonrails.org/t/dislpaying-validation-errors-from-one-one-model-to-view-of-another/65965/3 "2012-12-18T09:28:57Z")

</div>

> It looks like you’re not outputting your errors on your view.

> If you go to your terminal/command line and try the following:

> 

> type ‘rails c’ to enter the rails console. Here we go do a quick bit of testing to see if the errors are being captured.

> type ‘user = User.new’, this’ll output a new User object.

> type ‘user.errors’ If it returns Nil then you have a different problem otherwise it’s a case of just displaying your errors.

> 

> In your view you could do something like…

> 

> \<% if @user.errors %\>

> 

> There was an error, please see below.

> 

> \<% @user.errors.full\_messages.each do | msg | %\>

> - \<%= msg %\>

> \<% end %\>

> 

> 

> \<% end %\>

> 

> I hope that helps.

> 

> 

I was sending the errors to the view from the controller. I found out that since the errors where not from the base model (User) so it wasn’t displaying them. Once I added them to the base using errors.add(:base, “Error”), it started displaying the errors.
