Activity
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.
Posted in Refile :fill does not work for me
I'm not quite sure how the AWS storage works with the resized images. I'm guessing it downloads a copy of the image to your server from S3 and then resizes it, but maybe it's slow to reprocess things.
I wouldn't consider myself a refile expert and I'm not using it in production anywhere, but I would post this on the Refile github issues: https://github.com/elabs/refile
Posted in PDF Receipts Discussion
I haven't yet, but really want to. Obviously the HTML to PDF will be way easier than how Prawn does it. The programmatic generation is no fun at all.
Posted in Setup MacOS 10.9 Mavericks Discussion
This is basically saying that you're not using the rbenv version of Ruby and you're using system Ruby which you don't want to do.
Try restarting your terminal and double check your ran all the commands. The output you should get from the "which ruby" is something like this "/Users/chris/.rbenv/shims/ruby" when it is set up correctly.
Posted in Idea for TimeClock Need Advice
I think current_clock_event
probably makes sense in the controller because you might need it for rendering in the views to remind the user it's not finished. Like you said, you'll need to be able to reference it from the model for proper scoping, so you may technically need it in both places if you add it to the model first and then make a controller method to make it easier to access.
It make sense to cache the value of total_hours
on the model after save so that you've always got a queryable value. Would definitely recommend that.
Posted in Native Mobile Options
I think most people have opted not to build a native app that's just a mobile browser because it doesn't provide a great experience.
That said, it's still the easiest way to go. I believe if you use something like Phonegap, you probably do not need to do as much with regards to building APIs. You basically just need to store the session cookie around so next time you launch the app the user is still signed in.
If you'd like to go the full native experience, you will have to do a lot more work with building the apps and the APIs to support them.
Are you leaning one way or the other?
Posted in Must Read / Must Watch
That was another really fantastic talk. All of Sandi Metz's talks are wonderful.
Posted in Links not working on production server
Congrats!! Glad you got it working even if it did take a few days ;-)
The first few setups I had with nginx had a bunch of the same problems. Eventually you start to realize what works and troubleshooting gets a lot easier. There are just so many moving parts, it can be hard to figure out where things are going wrong at the beginning.
Posted in Links not working on production server
Here's a question: do you have database migrations in your app?
Also this error is saying development
and you probably want production
. My mistake on that nginx snippet. You'll want to update that to say production
instead. This might be the cause of why nothing ran.
When you run the migrations with capistrano, you should see the migrations printed out in the logs when it works correctly.
Posted in Links not working on production server
Alright! Now we're onto something. I think what happened the first time was that Passenger wasn't actually serving up the homepage through Rails and instead it was just serving up a static file instead directly. This is good.
So now your database migrations need to be run on your server which you can do with cap deploy:migrate
Once that is done, then I think Rails should successfully boot and serve up your pages.
Posted in Links not working on production server
Ah! This makes much more sense. It's not Rails, but your nginx config that's wrong. I was a bit confused how Rails wouldn't be responding to those properly.
You might try simplifying your config there to this and seeing what happens:
server {
listen 80 default_server;
server_name 198.199.98.206;
passenger_enabled on;
passenger_app_env development;
root /home/deploy/resume/current/public;
}
See if that helps at all, if not there are a few other things we can check.
Posted in Links not working on production server
Got some links or code we can take a look at? I bet it's something pretty simple but one of those differences when deploying to production.
Posted in Idea for TimeClock Need Advice
I think it makes sense to have a ClockEvent that has both in and out events. It also sticks around so that you can remind people to clock out if it's past a set amount of time and they have an open ClockEvent because they forgot to clock out.
Calculations on that should be as simple as subtracting the out from the in times and you'll get your result in seconds which you can easily add up and convert to hours. It will also easily work across days and things like that.
current_clock_event
Could just be the last ClockEvent for the user where(clock_out_at: nil)
It would return the last incomplete one, or none at all so you could create a new ClockEvent instead.
I think you've got this pretty well thought out so far. The only thing will be handling the forgotten clock outs and how to remind users and set the actual time for it after the fact.
Posted in Must Read / Must Watch
I thought I'd start a thread of articles and videos that are super high quality for software developers. Things that make you think and improve your thinking and how you build products.
I'll start:
Posted in API Design Decisions
Gotcha. I guess if the responses are super slow because of that, then having separate resources for them makes sense so only certain requests are slow and you'll be able to load the regular data for the primary record quickly.
I wouldn't put the token in the url because it's not a resource itself.
One benefit of having the fields
in the query is that your API endpoint will not change in the future. You can always include more data simply by adding options. If you have /resource/dog
, /resource/cat
, etc your clients will need to be aware when these are deprecated, move, or new things are added. It's much less flexible than having a configurable fields
or includes
query param.
Posted in API Design Decisions
I guess my question is actually more related to performance. How are you handling the slow responses for those records? Are you just providing a really slow response to an API request? Are you sending webhooks at a later time with the result?