Rails : Heroku : Production ActionController :: InvalidAuthenticityToken

 

So I’m not sure if this is 100% causing it but I was able to replicate the error

To reproduce:
1) Open two browser windows of the same browser type (ie. 2 chrome windows)
2) Go to the login page in both windows
3) Login on one of the windows and then logout
4) Login on the other browser window and you’ll see the error

Logging out updates the csrf token but if the other login page isn’t refreshed it doesn’t get the updated token. Shouldn’t devise be handling this situation gracefully?

Continue reading

Ruby On Rails : Exception Handling Best practices

There are various ways to rescue from exceptions raised in Rails App.

The most basic is

begin
.........
rescue NameOfException => exc
   logger.error("Message for the log file #{exc.message}")
   flash[:notice] = "Store error message"
   redirect_to(:action => 'index')
end

Or you can render a static HTML file namely public/401.html or public/400.html.erb
Continue reading

Ruby : Not throwing exception even when divided by Zero : Only when operands are floating points

# Throws an Exception when both operands are integers
# However, if operand are floating point numbers then that is not the case
begin
 puts 'Enter the Number'
 quotient = gets.to_i
 puts 'enter the divider'
 divider = gets.to_i
 result = quotient/divider
 puts "The result is #{result}"
rescue ZeroDivisionError
 puts 'Cannot divide by zero'
 retry
end
# Output
Enter the Number
12
enter the divider
0
Cannot divide by zero
# Whole process within begin block retried
Enter the Number
# However
begin
 puts 'Enter the Number'
 quotient = gets.to_f
 puts 'enter the divider'
 divider = gets.to_f
 result = quotient/divider
 puts "The result is #{result}"
rescue ZeroDivisionError
 puts 'Cannot divide by zero'
 retry
end
# Output
Enter the Number
12
enter the divider
0
The result is Infinity

12.12/0.0
=> Infinity

# However
12/0
ZeroDivisionError: divided by 0