mysql - How to Encyrpt data after validation in Ruby on Rails? -
mysql - How to Encyrpt data after validation in Ruby on Rails? -
i using devise authentication, register. want save emailid in mysql in encrypted format. utilize gem 'aescrypt'.
my controller:
def create @dashboard_user = dashboarduser.new(dashboard_user_params) @dashboard_user.created_by=current_dashboard_user.username @dashboard_user.company_id=current_dashboard_user.company_id active_ind = "" email = @dashboard_user.email if params["active"] == nil active_ind = "0" else active_ind = "1" end @dashboard_user.active = active_ind @dashboard_user.email= aescrypt.encrypt(email, "password") respond_to |format| if @dashboard_user.save format.html { flash[:notice] = 'user created.' , redirect_to action: "index"} else @dashboard_user.email = email format.html { render :new } end end end
when seek save user, throws email invalid. removed validation email in model. though same error exists. problem is? if there way encrypt info after validation?
thanks in advance.
how validate email? utilize custom method decrypt before validate against (for e.g.) regex. alternatively, can utilize activerecord callbacks. in case, after_validation
can useful :)
after_validation(on: :create) self.email= aescrypt.encrypt(email, "password") end
mysql ruby-on-rails database ruby-on-rails-4 device
Comments
Post a Comment