and it kept on printing my error message as Errors\nError message 1\nError message2 - note that the newline characters were being escaped and rendered literally# rjs render a javascript alert on the client
page.alert 'Errors\nError 1\nError 2'
I found this informative post which lead me to change my code from using single quotes to using double quotes - nasty.
# this one will output the newlines in the javascript alert message
page.alert "Errors\nError 1\nError 2"
here is the final code, looping through each error on the model object (product in this case) and outputing a newline on the javascript alert for each error
# rjs file
page.alert "#{get_message_for_show_server_error}"# helper file
def get_message_for_show_server_error
__s = "Errors "
__@product.errors.full_messages.each do error
____s = s + "\n" + error.to_s
__end__return s
end
No comments:
Post a Comment