Ruby on rails Rails 5使用链接更新日期
我有一个带有accept\u date属性的合同模型 我想通过link_更新accept_日期,以使用自定义方法,该方法还可以更改其AASM状态。通过将视图中的参数作为link_传递给put,或者在控制器中作为link_传递给get,这样做更好吗 看法 控制器 另外,Time.now和Date.today与其他助手获取当前时间的区别是什么?它们是否依赖于t.Date t.Time和t.datetime?我可以使用Date.today作为t.time属性吗Ruby on rails Rails 5使用链接更新日期,ruby-on-rails,ruby-on-rails-5,Ruby On Rails,Ruby On Rails 5,我有一个带有accept\u date属性的合同模型 我想通过link_更新accept_日期,以使用自定义方法,该方法还可以更改其AASM状态。通过将视图中的参数作为link_传递给put,或者在控制器中作为link_传递给get,这样做更好吗 看法 控制器 另外,Time.now和Date.today与其他助手获取当前时间的区别是什么?它们是否依赖于t.Date t.Time和t.datetime?我可以使用Date.today作为t.time属性吗 我使用了上面的方法,数据库显示提交,但没
我使用了上面的方法,数据库显示提交,但没有存储任何内容。您可以在更新状态后直接添加方法,如下所示,因此需要写入控制器的方法,使用PUT而不是GET,因为您正在更新某些内容 您的_model.rb
event :aasm_accept do
transitions from: :nothing, to: :everything, after: proc { |*_args| update_date_value }
end
def update_date_value
# your business logic
end
.current和.now的区别是.now使用服务器的时区,而.current使用Rails环境设置的时区。如果未设置,则当前值将与当前值相同
Date.today将为您提供今天的日期,不带时区。
Time.current将为您提供当前时间,并在rails应用程序中配置时区
def custom_method
@contract.aasm_accept!
@contract.update(contract_params) # if put
@contract.update_attributes(accept_date: Time.now) # if get
event :aasm_accept do
transitions from: :nothing, to: :everything, after: proc { |*_args| update_date_value }
end
def update_date_value
# your business logic
end