-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set att_accessors from parameters hash #7
Comments
Does it work like you suggest in ActiveRecord? |
I believe so. I find it usefull usually for setting getting unencrypted_passwords, and confirmation password. attr_accessor :password, :password_confirmation end u = User.new({:password => "test", :confirmation_password => "test"}) puts u.password puts u.confirmation_password class SimpleUser < SimpleRecord::Base attr_accessor :password, :password_confirmation end u = SimpleUser.new({:password => "test", :confirmation_password => "test"}) puts u.confirmation_password If you have access see Ch 11 of Agile Web Development with Rails 2 for a more detailed example |
Ok, I'll look at it soon. In the meantime, you could just set it with u.confirmation_password = "test" |
Actually did this in my model: def self.new_params(params) user = User.new params.each do |param|
user # return user end |
Using simple_record, if you have a model with attr_accessor(s), the attr_accessors are not set if their value is present in the params hash for new objects.
class Foo < SimpleRecord::Base
has_attributes :stuff
attr_accessor :bar
end
f = Foo.new(:bar => "test, :stuff => "yep")
f.stuff # puts "yep"
f.bar # puts nil instead of "test"
I came up with this: http://gist.github.com/609851
The text was updated successfully, but these errors were encountered: