Ruby on Rails Wednesday, July 25, 2012

try to write this 

<% if @variable_name.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@ variable_name .errors.count, "error") %> prohibited this user from being saved:</h2>

      <ul>
      <% @ variable_name .errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>


Regards,
Vishal Singh






On Thu, Jul 26, 2012 at 11:12 AM, Manoj M. <lists@ruby-forum.com> wrote:
Ace S. wrote in post #1070147:
> Manoj,
>
> Open up the console (rails c), and then create a new User (or whatever
> model you want) like this:
>
> u = User.new
>
> Check if this user is valid:
>
> u.valid?
>
> This should result in false! if NOT, then you dont' have any errors.
> Then
> you have to look at you validation lines in the model...
>
> If it is false then try:
>
> u.errors
> u.errors.full_messages
>
> this SHOULD give you an array of error messages. If not, there's
> something
> wrong.



>
> Now go back to your view and insert
>
> <p>ERRORS: <%= @object.errors.full_messages %> !!! %></p>
>
> into your view. Of course the @object must match the one you are making
> the
> form for.
>
> Tell me what you see then.
>
> Cheers
> ace






Dear ace,
          i tried with console it just works fine that showing
error_message ["Name can't be blank"] when i gave a.errors.full_messages
where a is a new object, but am unable to print the error message in
view page,where only empty array is displayed, i have no idea what to
do, its been more than 4 days i have stucked please help me out,
expecting your help more.


regards,
manoj

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment