我最近在我的机器上安装了纱线,但之前使用的是npm.对于我在React中的当前项目,我想再次使用npm.
但是,如果我运行create-react-app,它是用纱线构建的.
如何切换以便使用npm创建它?
在我的应用中,用户可以保存指定日期的销售报告.我现在要做的是查询数据库并仅选择最新的销售报告(所有那些在我的表中具有最大日期的报告).
我知道如何按日期对所有报告进行排序并选择具有最高日期的报告 - 但我不知道如何检索具有最高日期的多个报告.
我怎样才能做到这一点?我正在使用Postgres.
我正在建立一个减肥应用程序.为此,在我的应用程序中每个用户has_one :profile和has_many :weights.每个档案belongs_to :pal.为了让我的应用程序工作,我需要一个名为SMR的值,它基本上是一个公式,它将用户的大小,年龄和性别(来自配置文件表),用户的当前权重(来自权重表)以及来自朋友桌.
我能够在profiles_controller.rbshow action中计算SMR,并在配置文件show.html.erb中显示它.
我现在有两个问题:
profiles_controller.rbshow动作中进行此计算是正确的还是应该在profile.rb模型中进行?如果我应该在模型中这样做:我该怎么做(代码应该如何)?我是Rails世界的新手,所以也许我的问题真的是noob问题.
profile.rb
class Profile < ActiveRecord::Base
belongs_to :user
belongs_to :pal
belongs_to :goal
def age
if birthdate != nil
now = Time.now.utc.to_date
now.year - birthdate.year - (birthdate.to_date.change(:year => now.year) > now ? 1 : 0)
else
nil
end
end
end
Run Code Online (Sandbox Code Playgroud)
weight.rb
class Weight < ActiveRecord::Base
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
pal.rb
class Pal < ActiveRecord::Base
has_many :profiles
end
Run Code Online (Sandbox Code Playgroud)
profiles_controller.rb(仅显示操作)
def show
@pal …Run Code Online (Sandbox Code Playgroud) 我一年四季都有这样的数组:
const days = ["2019-01-01", "2019-01-02", "2019-01-03" ...]
Run Code Online (Sandbox Code Playgroud)
我有一个对象可以保存特定日期的计划和完成的任务:
const tasks = {"2019-01-01": {"planned": 3, "completed": 2,}, "2019-01-03": { "planned": 1, "completed": 0 }, "2019-01-10": { "planned": 1, "completed": 1} ... }
Run Code Online (Sandbox Code Playgroud)
我想要的是一个新对象,该对象包含整天的信息(无论任务是否计划和完成),如下所示:
const tasksNew = {"2019-01-01": {"planned": 3, "completed": 2}, "2019-02-02": {"planned": 0, "completed": 0} ...}
Run Code Online (Sandbox Code Playgroud)
我知道这在某种程度上可以与reduce一起使用,但目前我无法帮助自己。
我的Rails 5应用程序中有一个命名空间资源,并且需要正确的表单.
我在Rails 5中的Platform脚手架给了我:
<%= form_with(model: platform, local: true ) do |form| %>
Run Code Online (Sandbox Code Playgroud)
在Rails 4中,我将包括我的命名空间('customer'),如:
<%= form_for [:customer, @platform] do |f| %>
Run Code Online (Sandbox Code Playgroud)
那么Rails 5中的等价物是什么?