Skip to content

Instantly share code, notes, and snippets.

@benphelps
Created August 29, 2012 02:37
Show Gist options
  • Save benphelps/3506268 to your computer and use it in GitHub Desktop.
Save benphelps/3506268 to your computer and use it in GitHub Desktop.
class ArmorItem < ActiveRecord::Base
attr_accessible :armor_tier_id, :bonus_id, :enchant_id, :name, :stat_set_id
belongs_to :armor_tier
belongs_to :enchant
belongs_to :bonus
belongs_to :stat_set
attr_reader :stat, :agility
def stat
StatSet.find(stat_set_id)
end
def agility
ArmorTier.find(armor_tier_id).agility + StatSet.find(stat_set_id).agility
end
# NoMethodError: undefined method `agility' for #<ArmorTier:0x007fdf7ac7e410>
end
1.9.3p194 :004 > character.armor.hands
ArmorItem Load (0.1ms) SELECT "armor_items".* FROM "armor_items" WHERE "armor_items"."id" = ? LIMIT 1 [["id", 1]]
=> #<ArmorItem id: 1, armor_tier_id: "2", enchant_id: "", bonus_id: "", created_at: "2012-08-29 01:23:00", updated_at: "2012-08-29 01:44:51", name: "Gloves", stat_set_id: 1>
1.9.3p194 :003 > character.armor.hands.agility
ArmorItem Load (0.2ms) SELECT "armor_items".* FROM "armor_items" WHERE "armor_items"."id" = ? LIMIT 1 [["id", 1]]
ArmorTier Load (0.2ms) SELECT "armor_tiers".* FROM "armor_tiers" WHERE "armor_tiers"."id" = ? LIMIT 1 [["id", "2"]]
NoMethodError: undefined method `agility' for #<ArmorTier:0x007fdf7ac7e410>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment