嗨我目前在我的项目中使用momentjs我的日期和我在减去2个日期时遇到一些麻烦.
以下是我的样本日期:
2016-10-08 10:29:23
2016-10-08 11:06:55
Run Code Online (Sandbox Code Playgroud)
香港专业教育学院尝试使用diff并从momentjs的指南文档中减去,但我什么也没得到.
如果减去日期超过24小时怎么办?
事先提前.
我遇到运行我的rails服务器的问题.我在初始化程序中设置了abstract_mysql2_adapters,包括:
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
end
Run Code Online (Sandbox Code Playgroud)
它解决了我的rake db:migrate问题,但是当我尝试运行我的rails服务器时,它给了我这个错误.
C:/Users/XXXX/Documents/RoRCmS/simple_cms/config/initializers/abstract_mysql2_adapter.rb:2
<class:Mysql2Adapter>': uninitialized constant ActiveRecord::ConnectionAda pters::Mysql2Adapter::NATIVE_DATABASE_TYPES (NameError) from C:/Users/John/Documents/RoRCmS/simple_cms/config/initializers/abstract_mysql2_adapter.rb:1:in:in'from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.0.0 /lib/rails/engine.rb:609:block (2 levels) in <class:Engine>' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.0.0/lib/rails/engine.rb:608:in每个'来自C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.0.0/lib/rails/engine.rb:608: inblock in <class:Engine>' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:ininstance_exec'from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:inrun' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:inblock in run_initializers'from C:/ Ruby23- x64/lib/ruby/2.3.0/tsort.rb:228:block in tsort_each' from C:/Ruby23-x64/lib/ruby/2.3.0/tsort.rb:350:in来自C:/Ruby23-x64/lib/ruby/2.3.0/tsort.rb的每个_trongly_connected_component' 中的块(2个级别):431:ineach_strongly_connected_component_from' from C:/Ruby23-x64/lib/ruby/2.3.0/tsort.rb:349:inblock in来自C:/Ruby23-x64/lib/ruby/2.3.0/tsort.rb:344:each' from C:/Ruby23-x64/lib/ruby/2.3.0/tsort.rb:347:in来自C:/Ruby23-x64/lib/ruby/2.3.0/tsort.rb的调用':347:ineach_strongly_connected_component' from C:/Ruby23-x64/lib/ruby/2.3.0/tsort.rb:226:in来自C的tsort_each':/ Ruby23-x64/lib/ruby/2.3.0/tsort.rb:205:tsort_each' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in来自C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.0的run_initializers' .0/lib/rails/application.rb:215:在initialize!' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:inC语言的method_missing'中:/Users/John/Documents/RoRCmS/simple_cms/config/environment.rb:5:in require'from …
我正在创建一个spring mvc使用maven and Hibernate作为其数据库,我在JPA图编辑器上遇到问题我正在使用Eclipse火星.
在项目构面中启用JPA并在其中添加实体后persistence.xml,每次单击Open diagram它都会显示错误
diagramTypeProvider不能为null
嗨,我是Bcrypt的新手,我想知道如何正确使用此gem,到目前为止,我已经能够对密码进行哈希处理,但是在将其与用户输入的密码进行比较时,它不匹配。
这是我用于加密和登录的代码。
def self.login(user)
hashed_password = encrypt_password(user["password"])
result = User.where({:username => user["username"], :password => hashed_password})
return result
end
def self.add_user(user)
hashed_password = encrypt_password(user["password"])
result = User.create({:username => user["username"],
:password => hashed_password,
:firstname => user["firstname"],
:middle_initial => user["middle_initial"],
:lastname => user["lastname"],
:advisory_class => user["advisory_class"]})
return result
end
def self.encrypt_password(password)
password_salt = BCrypt::Engine.generate_salt
password_hash = BCrypt::Engine.hash_secret(password,password_salt)
end
Run Code Online (Sandbox Code Playgroud)
在add_user中,使用登录功能登录时,我正在使用crypto_password功能对其进行加密。密码与数据库中加密的密码不匹配。即时消息,我确定自己的做法不正确,您能指出我做错了什么吗?谢谢。
我想知道从另一个类调用函数时是否有一种最简单的方法来摆脱“自我”。例如,我这里有一个具有函数的类。
module Portfolio
class Main < Sinatra::Base
def self.create_user(username,password,confirm_pass,fullname)
@creation_flag = false
begin
if password == confirm_pass
@creation_flag = User.create(username: username,password: password,full_name: fullname).valid?
end
rescue Exception => e
puts 'Error Occured: '+e.message,""
end
return @creation_flag
end
def self.
end
end
Run Code Online (Sandbox Code Playgroud)
要使用这个,我需要声明self.create_user(params goes here)
有没有办法摆脱自我?
提前致谢。