12

I am getting the following error in my Rails 3.2 functional tests:

ActionView::Template::Error: undefined method `error_messages' for # <ActionView::Helpers::FormBuilder:0x007ff8ad00d3b0>

The view code that is creating the error:

<%= form_for [@camp, @program] do |f| %>
  <%= f.error_messages %> # problematic code
  <%= f.label :name %>
<% end %>

Here is the code in my controller that is calling the above view code:

render :action => "edit", :status => :bad_request

And here is the test I am running:

test "update a program with a bad request" do
  put :update, 
    :id => programs(:traditional).to_param, 
    :program => {
      :min_age => "a" 
    },
    :camp_id => camps(123).uri

  assert_response :bad_request
end

Does anyone have any insight into why this error is occurring in a Rails 3.2 app?

Thanks!

linusthe3rd
  • 3,455
  • 3
  • 28
  • 43
  • 2
    read: http://apidock.com/rails/ActionView/Helpers/FormBuilder/error_messages see also: http://stackoverflow.com/questions/3873190/f-error-messages-in-rails-3-0 –  Apr 03 '12 at 22:15
  • 1
    THANK YOU - i was looking for some documentation saying this method was deprecated but nothing was turning up. – linusthe3rd Apr 04 '12 at 04:09
  • 1
    Better way. http://stackoverflow.com/questions/3873190/f-error-messages-in-rails-3-0#answer-13246663 – Sony Mathew Mar 04 '16 at 10:56

1 Answers1

24

try the following code to iterate all errors, if any.

<%= form_for [@camp, @program] do |f| %>
   <% @program.errors.full_messages.each do |msg| %>
      <p><%= msg %></p>
   <% end %>
<%= f.label :name %>
<% end %>
Prashanth
  • 1,388
  • 2
  • 11
  • 26
  • 1
    It should be done via partial rendering. `render partial: 'error', collection: @program.errors.full_messages` – FUT Jun 25 '13 at 08:04