unexpected keyword_do_block syntax error in ability.rb (rails 3.2.0rc2) #548

mixellent opened this Issue Jan 19, 2012 · 2 comments


None yet
2 participants

So I did the mistake of updating my rails version to 3.2.0.rc2. But it seems that of all the plugins that I am using (including devise,omniauth and others) only CanCan is still complaining.

The problem occurs inside the Ability.rb file, where as soon as I use a block statement (see below for example)

can [:update, :destroy], Trip, do |trip|
trip.try(:user) == user

I am getting the error "unexpected keyword_do_block" and "unexpected keyword_end, expecting $end". As soon as I remove all my block statements, I am not receiving any errors anymore. Note that my code was working perfectly before upgrading the rails gem.

Here is a tracktrace:

syntax error, unexpected keyword_end, expecting $end):
activesupport (3.2.0.rc2) lib/active_support/dependencies.rb:469:in load' activesupport (3.2.0.rc2) lib/active_support/dependencies.rb:469:inblock in load_file'
activesupport (3.2.0.rc2) lib/active_support/dependencies.rb:639:in new_constants_in' activesupport (3.2.0.rc2) lib/active_support/dependencies.rb:468:inload_file'
activesupport (3.2.0.rc2) lib/active_support/dependencies.rb:353:in require_or_load' activesupport (3.2.0.rc2) lib/active_support/dependencies.rb:502:inload_missing_constant'
activesupport (3.2.0.rc2) lib/active_support/dependencies.rb:192:in block in const_missing' activesupport (3.2.0.rc2) lib/active_support/dependencies.rb:190:ineach'
activesupport (3.2.0.rc2) lib/active_support/dependencies.rb:190:in const_missing' cancan (1.6.7) lib/cancan/controller_additions.rb:349:incurrent_ability'
cancan (1.6.7) lib/cancan/controller_resource.rb:203:in current_ability' cancan (1.6.7) lib/cancan/controller_resource.rb:77:inload_collection?'
cancan (1.6.7) lib/cancan/controller_resource.rb:33:in load_resource' cancan (1.6.7) lib/cancan/controller_resource.rb:25:inload_and_authorize_resource'
cancan (1.6.7) lib/cancan/controller_resource.rb:10:in `block in add_before_filter'



I just found the cause for this issue, which is actually not related at all to Rails version.

The problem was the comma just before the 'do' syntax:

can [:update, :destroy], Trip, do |trip|
trip.try(:user) == user

Changing it to:

can [:update, :destroy], Trip do |trip|
trip.try(:user) == user

has fixed my issue.

@mixellent mixellent closed this Jan 19, 2012

Huh. Fixed for me as well. Was this related to a change in the version of a gem? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment