ruby on rails - Accessing current instance model attributes for a static function -
i have 2 models: user & api, in api model have static function
# register account associated characters public def self.register_characters(apiid, vcode, userid) # fetch xml api = eaal::api.new("#{apiid}", "#{vcode}", "account") result = api.characters # pull characters result.characters.each |char| if character.find_by_charid(char.characterid.to_i).nil? character = character.new( :charid => char.characterid.to_i, :user_id => userid, :name => char.name, :corp => char.corporationname ) character.save api = api.new( :user_id => userid, :character_id => character.id, :apiid => apiid, :vcode => vcode ) api.save character.update_character end end end i need call method in user model on after_create filter. anyway try pass variables user api error register_characters method not getting apiid or vcode , when start rails server.
in user model call: after_create api::register_characters(:apiid, :vcode, :id) :apiid, :vcode , :id user model properties.
however: since error appears when try boot rails server i'm assuming method self.register_characters in api called on self without being invoked user model.
anyhow how work around ? should make standard method or ?
to make flow more readable, suggest define new method calling method want.
after_create :register_characters_on_the_api private def register_characters_on_the_api api.register_characters(apiid, vcode, id) end you need remove colons before parameters use attributes of instance. passing :apiid, instance, passes symbol , not apiid of instance.
Comments
Post a Comment