Tuesday, October 28, 2008

Ruby on Rails - try catch finally block equivalent - exception catching

Looking for Ruby equivalent for "try catch finally"?

I also have a problem with that from time to time ;)
Its "begin rescue ensure end"
begin
somecode()
rescue

puts "Error #{$!}"
ensure

this_code_will_execute_always()
end

Sunday, October 26, 2008

1 error prohibited this user from being saved - rails form error_messages

If you have validated errors you can see the following messages:

1 error prohibited this user from being saved
there were problems with the following fields:
....

annoying and not very accurate - aren't they?

If you want to change these default messages try to pass some extra params to the error_messages method:
form_for(@user,:url => { :action => "login" }) do |f| %>
f.error_messages(
:header_message => 'X errors, please find red marks',
:message => 'Following errors were found:')