-
Notifications
You must be signed in to change notification settings - Fork 426
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
Rails 4.0.1 encrypted attributes not getting saved #72
Comments
I have not yet tested with AR 4.x ... anyone? |
I'm getting this error on Rails 3.2.11 using Mongoid. I think my implementation is correct, but I'm still learning. Am I doing it wrong? Here's an example of what I mean: First, I create a new class with a field 'color' that should be encryptable.
Then I make a new instance. Color does not save to db.
Set the color again and, yes, it can be encrypted...
But again, the color is not saved to the db.
|
Confirming for rails 4.0.1 saving works |
This is getting quite fragmented, but I'm on Rails 4.0.0 and Mongoid 4.0.0, on the console I can build an object and get the encrypted value of a field. However nothing gets saved to db. The field I want to encrypt is called words. So on the model I use:
On the controller:
|
This is how I fixed my problem by changing the way the fields are declared on the model:
I followed the test for the mongoid adapter. Now the record gets saved on the DB (mongodb) which contains a fields called encrypted_words. Calling .words on an object returns the correct decrypted value. Not sure it is a feature, a documentation issue, bug. I've used attr_encrypted with AR and declaration was different. But it works now for me. |
I'm seeing this issue too:
However, if I do the following, it works correctly:
I've created a patch in my own branch to work around this, however, |
#75 may be a better solution to this. |
just a point that I get in trouble using the gem today for the first time, if you are trying to crypt your password and then you forget to run the command: be rails g migration AddEncryptedFieldsToModel encrypted_password:string encrypted_password_iv:string encrypted_password_salt:string The crypto field won't be saved to database and its a silent, no error is shown... hope it helps |
I was having the exact same issue described in this thread. @fernandes had the fix for me. Before switching to this gem I had rolled my own encryption solution which basically used custom setters and getters, making additional fields in the database unnecessary. Because this is how I had already approached the problem, it wasn't immediately obvious to me that I needed to add fields to the db. I think this requirement to add fields to the db should be made more obvious in the "Basic" section in the readme. EDIT: I actually didn't do exactly what @fernandes described. I just added a field for :encrypted_#{attribute} |
hey @jgautsch good to hear my comment pointed the solution, adding just :encrypted_#{attribute} is ok, I added :encrypted_#{attribute}iv and :encrypted#{attribute}_salt to use: mode: :per_attribute_iv_and_salt So I have an iv and salt per attribute, if you would like to understand better why use this mode, check this issue: #32 |
I am also having this problem. I just added attr_encrypted to my ActiveRecord model with I can create instances of the model fine in the console, and the encryption works in the console, but when I save the record, the "encrypted_cred_key" field is NULL, and once I reload the console the |
all problems I've seen with this description come down to not naming the field correctly in the database. by default, if your attribute is "name", the database column should be "encrypted_name" |
Hi,
I'm running into an issue where attributes marked as attr_encrypt{ed,or} don't get saved to the db. When writing changes to the models I can read back the encrypted and decrypted values, but the encrypted_column_changed? methods return false and calling save doesn't write anything to the database.
I'm using Postgres and Rails 4.0.1. Any ideas?
Thanks.
Finbarr
The text was updated successfully, but these errors were encountered: