What did I do :)? In rails form has f.error_messages alwais empty. How can I fix/check this? Thx
+1
A:
Are you looking for error_messages_for :model?
After validation, this function will build a list of error messages for your view.
For example:
# users_controller.rb
def create
@user = User.new(params[:user])
if @user.save
redirect_to @user
else
render :action => 'new'
end
end
# view/users/new.html.erb
<%= error_messages_for :user %>
<% form_for @user do |f| %>
...
<% end %>
erik
2010-03-05 15:28:58
+1
A:
The AR#validate method fills the model's error hash with validation errors.
If between instantiating the model and the call f.error_messages you do not call validate (via AR#save or directly) the @errors hash never gets filled and the errors are never shown).
Also make sure you do not redirect ( the validated object gets lost and a new one is created and has no "filled" @errors hash ), but call render :action => ...
clyfe
2010-03-05 15:50:27