-
Notifications
You must be signed in to change notification settings - Fork 427
QuestionsAndAnswers
sebb edited this page Jul 26, 2011
·
2 revisions
I do not want to save the :key on the web sever or database at all, but, rather, have it only be memorized by the user and only sent when the user asks for the information. Is attr_encrypted a solution?
# your model
class User < ActiveRecord::Base
attr_accessor :key
attr_encrypted :credit_card, :key => proc { |user| user.key }
end
# your controller
def some_action
@user = User.find(params[:id])
@user.key = params[:key]
@user.credit_card # returns decrypted credit card number (if key is correct),
# otherwise raises an exception about an invalid key
end