The reason to add extra attributes as shown in my example is to allow for the accessor goodies provided by ActiveRecord for the model ob:
$ cat app/models/hit.rb class Test < ActiveRecord::Base attr_accessor :foo end $ ./script/console Loading development environment (Rails 2.2.2) >> test = Test.new => #<Test id: nil, name: nil> >> test.id = 987 => 987 >> test[:id] => 987 >> test["id"] => 987 >> test.foo = 'bar' => "bar" >> test[:foo] => nil #huh? >> test["foo"] => nil #huh? >> test.attributes.keys => ["id", "name"] #huh? ### add key/val via model ob's attributes: >> test['foo'] = 'bar' => "bar" #cool. >> test.foo => "bar" #cool. >> test[:foo] => "bar" #cool. >> test.attributes.keys => ["id", "foo", "name"] #cool. So, for your User example, if you changed the adding of password attrib as: ... user["password"] = "bar" ... then your orig code should work as you intended. Hope that helps, Jeff On Feb 15, 9:14 pm, rapdup <[email protected]> wrote: > Okay, I found a solution. It isn't very readable, but it works: > > user = User.new(:login=> "foo", :password=>"bar") # :password is not > a column in the db, but defined in the model using > "attr_accessor :password" (see initial post) > [:login, :password].each do |x| > getter = x # => :password > setter = (x.to_s << "=").to_sym # => :password= > original_val = user.method(getter).call > user.method(setter).call(some_new_val) > do_some_test(user) > user.method(setter).call(original_val) > end > > Any clean up suggestion? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

