Skip to content

Instantly share code, notes, and snippets.

@leifcr
Created December 19, 2011 09:52
Show Gist options
  • Save leifcr/1496371 to your computer and use it in GitHub Desktop.
Save leifcr/1496371 to your computer and use it in GitHub Desktop.
Rails 3.1 Helper Issue in production mode with cache_classes=true
#model page.rb
class Page < ActiveRecord::Base
STATUSES = %w[new published]
end
#Page helper module
module PageHelper
def possible_statuses(right)
statuses = Page::STATUSES
statuses.delete("publish") if (right != "can_publish")
statuses
end
end
possible_statuses("no_rights") # Should return ["new"]
possible_statuses("can_publish") # Should return ["new", "published"]
# if options.cache_classes = true
possible_statuses("no_rights") # Returns ["new"] OK
possible_statuses("can_publish") # Return ["new"] Not correct...
# if options.cache_classes = false
possible_statuses("no_rights") # Returns ["new"] OK
possible_statuses("can_publish") # Return ["new", "published"] OK
# Thought 1:
# It seems like the helper method is a bit "smart" and changes
# the const STATUSES even though statuses and STATUSES as variables
# with different cases shouldn't be equal
# What really happens is Ruby Object assignment.
# Read: http://stackoverflow.com/questions/2635156/object-assignment-and-pointers
# This won't happen i development because of classes beeing reloaded for each request...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment