[英]Using Ruby to track updated information?
The script I am trying to build works like this. 我试图构建的脚本就是这样的。
Right now I can do step 1. I'm struggling to get my application to save the number the user obtained in step 1. 现在我可以做第1步。我很难让我的应用程序保存用户在步骤1中获得的数字。
Ideally, this should work like a timer. 理想情况下,这应该像计时器一样工作。 The user starts the timer, goes for a drive, comes back, stops the timer, and his average speed is returned to him.
用户启动计时器,驱动器,返回,停止计时器,并将他的平均速度返回给他。
Is Ruby and Rails enough? Ruby和Rails足够吗? Or will I need some sort of AJAX or JavaScript?
或者我需要某种AJAX或JavaScript?
Ruby on Rails is enough. Ruby on Rails就足够了。 You can keep the starting time as data in step 1, and call that in step 3 or 4.
您可以将开始时间保留为步骤1中的数据,并在步骤3或4中调用该数据。
I think you're getting confused between how Rails, JS & Ajax work 我认为你对Rails,JS和Ajax的工作方式感到困惑
Rails is backend; Rails是后端; will handle your db & requests.
将处理您的数据库和请求。 JS / Ajax will process any front-end requests made directly by the client in the browser
JS / Ajax将处理客户端在浏览器中直接发出的任何前端请求
Make Another Model 制作另一种模式
What you're asking is actually quite simple if you break it into modular pieces 如果你把它分解成模块化的部分,你所要求的实际上非常简单
User
doesn't have many miles; User
没有多少英里; a User's
Trip
has many miles User's
Trip
有很多里程 Trip
Trip
Trip
will have many miles Trip
都会有很多里程 TripMiles
which you'll be able to store the miles in TripMiles
,您可以将其存储在里程中 created_at
times to see how many miles per hour created_at
次数查看每小时的里程数 Here are some examples: 这里有些例子:
#app/models/user.rb
Class User < ActiveRecord::Base
has_many :trips
end
#app/models/trip.rb
Class Trip < ActiveRecord::Base
belongs_to :user
has_many :miles, :class_name => "TripMile"
end
#app/models/trip_mile.rb
Class TripMile < ActiveRecord::Base
belongs_to :trip
end
trips
id | user_id | created_at | updated_at
trip_miles
id | trip_id | created_at | updated_at
This will allow you to set the trip
as a specific record, and then add as many miles to it through the trip_miles
model. 这将允许您将
trip
设置为特定记录,然后通过trip_miles
模型trip_miles
添加尽可能多的里程。 How you add these will depend on your front-end, but it will all be Rails 你如何添加这些将取决于你的前端,但它将全部是Rails
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.