Brian Schwartz


1,250 Experience
0 Lessons Completed
1 Question Solved


Posted in macOS sierra working w/ Ruby / Rails / RBENV?

Thanks everyone. Working for me with everything thus far (love logging in with my apple watch) Chris ran into problems with sqlite3. Chris did you ever get those resolved?

Posted in macOS sierra working w/ Ruby / Rails / RBENV?

Curious if anyone has tested it? Don't want to upgrade until I know everything in my stack works correctly without a ton of pain.


Posted in Refile uploading via rails console

Me too!

Another question (I could create another thread if you don't have a quick answer).

I have a whole bunch of images already stored on s3 that I don't want to transfer every time I run seeds. Any way you can think of save them out in a seeds file that doesn't force a re-upload? Is that refile ID anyway tied to an item from S3?


Posted in Refile uploading via rails console

Solved it. Apparently my migration had my image saved as the wrong name (image instead of image_id).

Posted in Refile uploading via rails console

No errors. Image is nil both in database and when I load it fresh out of database. I have FriendlyId on that model as well as RankedModel, so I'm wondering if they have anything to do with it. I'm going to disable temporarily to see if they do.

Posted in Refile uploading via rails console

So I'm using Refile and I'm trying to migrate some existing data that I need when I seed the database (migrating to Refile from existing solution and need to keep existing data).

When I try testing my data in the console, it saves the image meta data, but not the image.

Here's what I'm doing example:

class Page < ActiveRecord::Base
  attachment :image 
  attachment :full_size_image


page = "Issue 3 Cover", title: "Issue 3 Cover", issue_id: 3, position: 1, center_image: true, in_index: false, published: 1)
page.image ='/Users/creativereason/Downloads/issue-10_001-issue-10-cover-small.jpg')

The result of that is a the metadata being saved, but the image being nil in the database. As far as I can tell, the data is in the bucket on S3 I'm using too.

Any ideas?

Posted in Better Errors ignore 404 errors

I guess that works (testing 404 manually). I'm intentionally throwing a ActiveRecord::RecordNotFound when a page in my app is visited but not published yet. So I wanted to make sure it was throwing it. I'm getting the Better_Errors error page with that exception, so I guess it's working.

Posted in Better Errors ignore 404 errors

I'm using better_errors gem to track errors better. Any idea how to make it ignore 404 or ActiveRecord::RecordNotFound exceptions? I want to test to make sure my 404 page is working correctly and I'm seeing better errors screens instead.


Yep, pepkac will get you every time. I had log rotation on, but I've still burned through a large number of log files in last 3 weeks.

Also, in case anyone finds this UFW is a iptables wrapper that makes it super easy to insert new rows.

Also, request for a show about Fail2Ban which does a good job of automating the blocking of brute force attempts at SSH, POSTs, etc.

Never mind! Firewall rules were in wrong order! :)

Posted this to serverfault too, but I'm still stuck:

I have a server that keeps trying to brute force hack via xml-rpc post on a wordpress site (I know, I know). I've blocked the ip address in nginx.conf and noticed that I kept getting these errors in the log file, and since they are brute force, this is just a very, very slow DDOS (because they are causing log files to take space).

[error] 30912#0: *4600 access forbidden by rule, client:

I've searched for log file changes but it looks like it's all or nothing on 403 errors and that wouldn't help me (wouldn't see any others).

To combat this, I've tried blocking by firewall (using UFW wrapper around firewall tables) and added an entry on that shows as this in status:

Anywhere DENY XXX.XXX.X.XXX (redacted)

However, even after enabling the firewall rules, and checking to make sure they are running, when tailing the log file I still the same error entries 403 errors writing over and over again.

Any thoughts on how to make this hacker go away without filling up the log file? It's a virtual 14.04 LTS server.

Any thoughts or ideas? I'm getting error.log entries every second or more from this same ip address.

Posted in Single Table Inheritance: Good spot or not?

I have two simple models I'm about to create in an existing Rails app. One is a NAICSCode which has the following attributes: company_id, code, name, and description, the other is SICCodes which has those same attributes, plus an attribute called year_first_appeared.

Both models are just wrappers around data storage for those attributes (no individual methods at this point), and both belong_to Company (which does have functionality and a purpose).

If these actually did anything besides store related data, I can see an advantage of creating a Code object (model) and using STI, with SIC or NAICS being a type.

Without any methods is there any benefit besides having one less table in the database?

Posted in JSON for Rails delegated attributes?

Chris, thanks. That worked great. Here's how I implemented this (which seems like it's working great).

@prospect.attributes.each do |attr_name, attr_value|
  json.set! attr_name, attr_value
end do |attr_name, attr_value|
  json.set! attr_name, attr_value unless attr_name == "id"

Posted in JSON for Rails delegated attributes?

Also, maybe another thought would be to override to_json for my Prospect and Lead models. Maybe I'll look there next (b/c ActiveModel Serializer could be overkill for this need).

Posted in JSON for Rails delegated attributes?

In one of my Rails apps, I have the following architecture (as part of a current refactoring):

  • Contact (a lot of attributes common to all people)
    • Prospect (specific attributes to just prospects, delegates other attributes to contact
    • Lead (specific attributes to leads, delegates common attributes to contact

Both Prospect and Lead do the following (below). I've gone back and forth in testing on STI and / or MTI inheritance using acts_as gem, but this is actually the cleanest way for me for now (because leads and prospects are both contacts, but not mutually exclusive).

delegate :first_name, :last_name, :address_1, :address_2, :address_3, :zip, :city, :state, :email_address, :phone_number,
       :client_id, :unsubscribed, :original_list_id, :to => :contact

My code that isn't refactored yet renders prospect objects instances to json to use attributes in various client side needs. Using JSON the delegated attributes don't show up. I know you can explicitly declare methods in render :json declarations (and I do so elsewhere, on calculated columns), but this is clumsy for a lot of attributes in potentially multiple controllers. Using includes would require parsing them as separate object attributes (instead of these attributes appearing to be coming from Prospect or Lead).

I've looked into ActiveModel Serializer and it seems like it fits my needs, but I can't find a way to make it work with delegated attributes. Any ideas or suggestions would be appreciated...

Posted in Javascript frameworks videos?

+1 for React here too. :)

Posted in Javascript frameworks videos?

Hey Chris,
Just curious if you would plan on adding any videos using Angular, Ember or Backbone with Rails?

Ok, I figured it out. I had deploy user as the owner of the app directory. Switched to www-data (which I didn't realize was still needed in nginx) and it's rendering correctly. Maybe add something about who should own / execute the app directory in the deploy guide?

I am stuck on capistrano 2 because of the sheer volume of deployments I have in there. So maybe it does this when you run cap deploy:setup? Or maybe it needs to be part of the recipe?

Nothing in the nginx error.log when I get those 404's either.

Same problem (after that change and restarting nginx and touching restart file). None of the files in public folder are being served (with or without a subdirectory). Even favicon.ico or 500.html.

But the files trying to load from my theme are giving me errors in production.log (the one I posted before). If I try to directly to navigate to 500.html or favicon I get no errors (my application layout loads instead of serving the static files).

Could this be a permission issue on public directory?

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.