Chris Oliver

Joined

292,890 Experience
93 Lessons Completed
295 Questions Solved

Activity

Posted in How to make a good Sidekiq job?

For more database-related things, a transaction is good because it gives you the ability to do multiple changes to the data without them partially being finished.

With APIs it is a bit harder since you cannot roll back the execution of the API request. In this case, you basically want to log something immediately after the API request is finished denoting that this part of the job has been completed.

In the case of sending an email, you will need to make sure that your code after a successful send is very simple. Immediately after sending, you will want to write a record on the user that the email was sent. At this point, if the job died and was retried, you would be able to check if that email was sent and then cancel this job.

Posted in Ruby issue when doing cap deploy production

So creating the database and creating the tables are separate. The migrations are what tells the database which tables and columns to add and the database is just the one place to store everything. You'll want to make sure the migrations run on the server.

You should be able to do that with cap deploy:migrate

Posted in Setup Ubuntu 14.04 Trusty Tahr Discussion

Well, the issue isn't that the packages aren't maintained properly. It's that the software doesn't get upgraded to be compatible with the latest Ruby releases always. Sometimes you have code that works on specific versions of Ruby and that means you will need to install that version specifically on your server. That's why everyone recommends using a Ruby version manager of some kind like rbenv to handle this. Once you get the hang of it, it goes smoothly, but at first it can be daunting and a bit of a pain to set up.

Posted in Ruby issue when doing cap deploy production

Hmm, not sure what's wrong exactly. Also you could just create the db after getting into the psql console by doing CREATE DATABASE your_database_name. Then you need to grant all privileges to that user on the new db.

Great reference for this stuff:
http://www.cyberciti.biz/faq/howto-add-postgresql-user-account/

Posted in Ruby issue when doing cap deploy production

Gareth - It is probably because your Postgres user doesn't have create database rights. You may want to either fix permissions on the user you are connecting with, or login as the postgres user and create the db manually.

Posted in Flexible Nested Attributes

I've been having a couple hiccups with the new version of Passenger and it's connection to the database. Going to revert back to Puma for a bit and that should solve the errors posting.

I think Cocoon technically calls these "nested forms" since you're dynamically adding new form fields for new objects.

Might need to correct me if I'm misunderstanding the issue here, but this is what I think is happening:
One thing that might be happening is that when the page re-renders your form actually renders using the @recipe and the assocations on it without using @contents variable. I think you probably have two options there. Either adding a scope into the association to order the contents or seeing if you can pass in @contents as the variable to use for rendering the fields.

Posted in Tracking Rails App Usage with Analytics

Yeah, that's correct. It only runs in the browser on a page view. You'll get very basic data with it.

Segment is fantastic for us because it allows us to track custom events and not just page views. We can keep track of "User signed up", "User subscribed", "User canceled" and then have all this information to see where people are dropping off. It's a different set of analytics which is more valuable at certain times than others. Getting a basic Google Analytics implementation and then figuring out what's important to measure later on is usually what I do. Basics first, then add some complexity as needed later.

Posted in Simple newsletter sign up?

Looking good! Glad you got everything figured out.

Yeah, it's one of the methods generated by the has_one association. The docs show it as "build_association" and "create association". http://apidock.com/rails/Ac...

Posted in Comments With Polymorphic Associations Discussion

You could do that by scoping the comments further by adding ".where(user: current_user)" to the query in the controller.

Posted in Simple newsletter sign up?

Oh awesome, glad you got it working! :)

Posted in Simple newsletter sign up?

That would happen from missing the method: "POST" parameter in your $.ajax call. When a form is submitted via GET, it sends all the fields over in the URL instead of in the body.

If you make sure that it's sending a POST through, then you should be set.

Posted in File Uploads with Refile Discussion

Ah it looks like it's sending webhooks back. Those are always a bit tough to test in development because your dev server isn't publicly accessible on the internet.

Thanks for sharing GoRails! :)

Posted in File Uploads with Refile Discussion

This looks super cool. I haven't used it before, so I'm not quite sure how they return the urls afterwards. I have previously seen a lot of people using https://www.filepicker.com/ in the past.

I think they're definitely great and give your users a lot of flexibility as well saving you from a lot of time managing the files and processing them. Would definitely recommend it if file uploading is something you don't really need to manage or customize too deeply.

Posted in Liking Posts Discussion

You'll need to make sure you pass the book into the partial because they have different scopes for local variables.

Posted in Liking Posts Discussion

So when you loop through each book, you need to reference the "book" local variable, not the "@book" instance variable when rendering the button. This is because the each yields the current book in the loop to the code inside the each block so it can run multiple times every book in the array.

Posted in Simple newsletter sign up?

Alright, I got an episode recorded for you! http://videos.gorails.com/medias/4h3x4wsnhp

Give it a watch and see what you think. I'm curious how you feel about the speed of the episode. I touched on a lot of things all at once but tried to break them down just enough. Hopefully you'll find it useful!

I think I'll try releasing this out as a full GoRails episode as well and see what people think.

Posted in Liking Posts Discussion

You can set up an association to get the liked books through the likes the user has. It follows basically the same format. Remember that your book variable from the each is actually a full Book record so you can print out the id, the title, or whatever just by changing what you reference. Here's an example that would list out the book titles that a user likes. (I haven't tested this so it may not work right off the bat)

class User
has_many :likes
has_many :liked_books, through: :likes, class_name: "Book"
end

<%= current_user.liked_books.each do |book| %>
<li><%= book.title %></li>
<% end %>

Posted in Setup MacOS 10.10 Yosemite Discussion

That's good to know. I'm curious as to why I've never had that issue, but I guess I'll make a note in there to restart your terminal just in case.

Posted in Sending emails with Mandrill Discussion

Glad you got it working! As an aside, one great way to test all this is to manually create and test your emails from the Rails console. It can help you poke around and find bugs like this quicker than going through the browser.