问题
I'm kind of a newb to RoR and I'm working on creating my first web app.
So...My question is, how do I create a user time sheet in RoR?
What I need to do is create a classroom time sheet for students' (Users) reading times at home.
The students (Users) are able to sign up and have a profile created. From there, I would like for them to have access to log in their reading time(s).
I have attached examples of just some simple timesheets that would work perfectly for this.
I just do not know where to start and have not been able to find any gems that could help me create this.
Time Sheet 1
TimeSheet 2
回答1:
Users: Ruby part
- Use Devise gem - it will save a lot of time for you.
Add Devise to user model (something like that: rails generate devise User
), then autogenerate basic Devise pages (sign in, sign up, etc), see Devise tutorials:
- https://launchschool.com/blog/how-to-use-devise-in-rails-for-authentication
- http://guides.railsgirls.com/devise
Also you'll probably need something like Job
model with fields user_id
, time_spent
, date
or something.
Timesheets: JS part
Time tracking is more front-end part of work, so you'll need to write some JS scripts for time tracking, which will monitor user activity and then send it to Job mobel on Rails side.
Track time spent on page (example):
var page_opened;
$(document).ready(function () {
page_opened = Date.getTime();
$(window).unload(function () {
page_closed = Date.getTime();
$.ajax({
url: "/save_user_time",
data: {
'timeSpent': page_closed - page_opened,
'job_id': job_id
}
})
});
}
Also you defenetly should take a look on some basic Rails tutorials for better understanding:
- http://guides.rubyonrails.org/getting_started.html
- https://www.codecademy.com/learn/learn-rails
来源:https://stackoverflow.com/questions/40898412/creating-a-user-time-sheet-for-a-ror-web-app