The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
Hey all, I'm trying to make crystal app with Kemal, Granite ORM on postgres. My question is I created one model that needs to update password to encrypted one. But on the build, It's giving error as...
instance variable '@password' of User must be (String | Nil), not Crypto::Bcrypt::Password
require "granite_orm/adapter/pg"
require "crypto/bcrypt/password"
require "logger"
require "kemal"
log = Logger.new(STDOUT)
log.level = Logger::WARN
class User < Granite::ORM::Base
adapter pg
before_save :prepare_data
field email : String
field password : String
timestamps
def prepare_data
if password = @password
log("#{password}")
@password = Crypto::Bcrypt::Password.create(password)
log("#{@password} | #{password}")
end
end
end
module Crystal::Chat
get "/" do
user = User.new
user.email = "test@test.com"
user.password = "pass1234"
user.save
"Hello World! #{VERSION}"
end
Kemal.run
end
extend self
inside the module
Hash.new( Int32, Int32 ){ 0 }
but it did not work.{% begin %} ... {% end %}
as explained here https://crystal-lang.org/docs/syntax_and_semantics/macros.html#pitfalls