Activity
I think when you set config.time_zone
that actually changes the database values and does not store them as UTC anymore. You can verify this by saving a time like 4pm and seeing if 4pm shows up in the database or a different time. If they are the same, then it means that it is not saving the times as UTC. If they are different, then that means it has converted it to UTC to save to the database.
I usually recommend saving always to UTC in the database so that in the future if you need to have custom times for all your users, you can adjust Time.zone
on the fly or use the local_time
gem.
Let me know what you find out about config.time_zone
because I always forget if it modifies the ActiveRecord time conversion or not.
I think usually the config.time_zone
complains when you set it to an invalid date option so it doesn't seem like that's the issue.
One thing to point out is that you should almost never use DateTime.now
and you should always go with Time.zone.now
just to be safe.
Maybe try swapping the DateTime
ones out with Time.zone
and see if that helps?
Posted in Must Read / Must Watch
This is so good. http://lwn.net/SubscriberLink/641779/474137b50693725a/
You can use Rails UJS directly to do that. I use this and the @form variable is just a jquery selector for the form
$.rails.enableFormElements @form
Thanks for the tips! I'm not a Vagrant expert, so #2 was new to me. The chef recipe used to install bundler for me, but it doesn't seem to anymore either. Super annoying.
No worries! I'm going to re-watch it tonight because I'll probably have the same feeling and get you a much cleaner example including the controller that I eluded to but never showed. Showing the controller will clear up a lot of things I think.
I might re-record it with a clearer example. It could be explained a lot better.
Well, we actually eager load the sections, steps and privacy settings at the beginning through the course. That's all done and was the obvious thing to look at for performance, but the real bug here is more subtle in that we've loaded the object already but weren't referencing it correctly.
Those are all equally important in building performant responses though!
Pretty soon! It's a lot of content so I need to make sure I plenty of time to plan it all out.
Posted in Idea for TimeClock Need Advice
You gotta start somewhere. It's like art, just start painting. You can't plan a masterpiece, you've got to feel it out as you go (which is my main issue with TDD).
Last night I rewatched these two episodes and they gave me a lot of ideas on maintainable code:
https://www.youtube.com/watch?v=yhseQP52yIY
https://www.youtube.com/watch?v=mWo3oEwFFzM
Posted in Setup MacOS 10.10 Yosemite Discussion
Hey Sarah, if you haven't fixed this yet, the error basically says that your database password doesn't match what was set up with MySQL. If you used homebrew to install it, then the username is usually the same as the user you login as and the password is empty.
Posted in Idea for TimeClock Need Advice
Yeah refactorings are always really painful like that because you can't merge in the main application ever when it updates around this same code. This is where testing really shows its value, but versioning doesn't have a good way to handle this yet.
Posted in PDF Receipts Discussion
I will check it out! I did some research and can't remember why I picked prawn other than I saw enough other people using it and documentation seemed robust. That said, I bet wkhtmltopdf is way easier now that I've used Prawn more than a little.
The hardest part was building our completion certificates at OneMonth.com in Prawn. It was is finicky and time consuming.
Posted in Problem with upgrading to Rails 4.2.2
Haha! I was reading the title and was like hmm, I don't think I've upgraded to Rails 4.2.2 yet either. ;)
Posted in Idea for TimeClock Need Advice
If you're building this into an existing app, a branch makes sense. If you need to quickly prototype it without trying to fit it into the legacy code, it might make sense to try out a new app, but you'll still have to integrate it with the legacy code at some point. I'd probably go with the feature branch.
Posted in Recurring Events
Neat, I didn't know about Recurring Select. What kind of params does the recurring_select
field send over? Their Readme doesn't really explain that.
Posted in Active Record Associations
You should be able to do this:
class Partner
has_many :centers
has_many :classes, through: :centers
end
Which Rails will know how to query based upon the other associations in the Center class. It basically compiles those associations together into the proper joins for you when you use the through
option. You might have to tweak this a little bit for any class names or whatever that don't match up directly, but that should do the trick for you.
Posted in Idea for TimeClock Need Advice
Looks pretty good, but here's what I'd refactor:
class ClockEvent
belongs_to :user
scope :incomplete, -> { where(clock_out: nil) }
scope :complete, -> { where.not(clock_out: nil) }
end
class User
has_many :clock_events
def clock_event
@clock_event ||= clock_events.incomplete.last || clock_events.new
end
end
Some changes:
The scopes on the clock event make them useful for many other use cases, not just this one. Also I don't think you can use
.last
in the scope like you had, you'd want ahas_one
instead if you really wanted that or to use thelast
call attached to the scope like in my example'sclock_event
User
now hasclock_event
which simply returns their current event. First it looks up any incomplete ones and grabs the latest one and if that returnsnil
it will create a new associated ClockEvent in memory. I cache that to a variable since you'll probably reference it a few times in your views and this will be important so you either don't query the record many times or create a bunch of new ones in memory each time you access the method.The
completed?
method isn't required for this anymore either because we're using thenil
return value in the statement to trigger the|| clock_events.new
which is nice. Less code ftw, but you'll probably wantcompleted?
for rendering things in the view or logic elsewhere still.\
Hope that gives you some ideas! Looks great so far too.
Posted in Must Read / Must Watch
One of my favorite people on this planet, anything by Bret Victor is top notch. Here are three insanely good talks by him.
https://www.youtube.com/watch?v=PUv66718DII
https://www.youtube.com/watch?v=8pTEmbeENF4
https://www.youtube.com/watch?v=ZfytHvgHybA
Posted in Native Mobile Options
I think if you're shooting for something simple as a start, Phonegap and related options should work pretty well for you. I don't think they're awful experiences and they've gotten quite a bit better over the years. It's definitely worth a shot because your time investment will be so much smaller than trying to build a full API and native mobile apps.
From a quick google search, I found this and he builds a basic Phonegap app for a Rails app in under 15 minutes. Not too bad if you want to experiment with it and see what you get.