0

This is my edit_scheme.rhtml file in which i'm getting this error.

<%=stylesheet_link_tag 'showpage'%>
<%=stylesheet_link_tag 'easy'%>
<%= error_messages_for 'scheme' %>
<% form_tag({:action =>'updatescheme', :id =>@scheme},:multipart=>true) do %>
  <!--[form:document]-->
  <h2>Edit Scheme</h2>
  <%@role = Role.find(:first, :conditions =>["role_name=?",'Help Desk'])%>

<%= render :partial=> 'schemeform'%>
<!--[endform:document]-->

<tr style="text-align:right;">
<td></td>
<td> Status:</td>  
  <td> <%=radio_button :scheme, :status, "Active"%>Active 
  <%=radio_button :scheme, :status, "In-Active"%>In-Active</td>
</tr>
<p align="center" style="padding-top:10px;">
  <%= submit_tag 'Edit' ,:style=>"padding:2px;"%>&nbsp;&nbsp;&nbsp;
  <%if session[:role]=="Administrator"%>
  <%= link_to 'Back',:action=>'scheme_search'%>
  <%end%>
  </p>
<% end %>

The error refers to this line

<%= error_messages_for 'scheme' %>

What I'm Missing? Any help is appreciated!

Pavan
  • 33,316
  • 7
  • 50
  • 76
Nageswar
  • 27
  • 1

2 Answers2

0

If you want to list all errors for i.e. a product from a form:

<% @product.errors.full_messages.each do |msg| %>
  <li><%= msg %></li>
<% end %>

You should also test are there any errors at all.

<% if @product.errors.any? %>
   ...
<% end %>

This should work with a collection too.

enter08
  • 943
  • 1
  • 8
  • 11
  • if you had a collection of products? no it wouldn't work, not without iterating over each product (which is the part the asker is missing, I think) – sevenseacat Apr 17 '14 at 07:03
0

Try using the :object param as the second arg:

<%= error_messages_for 'scheme', :object => @scheme %>

I found this comment in the source of Rails 2.2 above the error_messages_for method:

# If the objects cannot be located as instance variables, you can add an extra <tt>:object</tt> parameter which gives the actual
# object (or array of objects to use):
#
#   error_messages_for 'user', :object => @question.user

https://github.com/rails/rails/blob/c6cb5a5ab00ac9e857e5b2757d2bce6a5ad14b32/actionpack/lib/action_view/helpers/active_record_helper.rb#L162

SoAwesomeMan
  • 3,226
  • 1
  • 22
  • 25