Part 2

Please note, an installation of ImageMagick is required for this lesson. We recommend using Homebrew to install this on OS X For Windows and Linux, please see the instructions on these pages: * http://www.imagemagick.org/script/binary-releases.p...
This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/intermediate-part-2
1 Like

Here’s a SO post that helps clarify some issues you may run into with Rails 4 about halfway through the video:

Also, Paperclip has a content type validator that I couldn’t get working until I discovered this:

1 Like

Looks like there’s a better workaround for validations:

In Rails 4, when you run the migration for the following_relationships table, you won’t be able to do it!

You have to jump a head a bit in the video and add more relationship logic to your User model before the migration will run.

Did you manage to make this work?

Hi @ryankbales, that error means that you are trying to render a nil, rather than the object you expect to have. Many of ActiveRecord’s finder methods will return nil if they fail to find a record, for instance User.find_by(email: 'fake-email') would return nil rather than a user (or raising an error).

You can force Rails to raise an error if you expect a user to be there, and not having one would be a problem. Just tack a ! on the end of the method name User.find_by!(email: 'fake-email')

All together this looks like:

# in your controller
@user = User.find_by(email: 'not-a-real-email') # => returns nil

# in your view, you expect @user to be a User object, but it is actually nil
<%= render @user %>

Okey dokey. After realizing that part of the solutions were already posted here, I finally got it working with one last step…Upgrading Imagemagick. Thanks for the help.

I’m not getting any errors, but the shouts won’t render on my dashboard show page, and on my user show page it’s listing the shout objects themselves <TextShout:0x007f83a96486b8> instead of the content. I’ve checked my code several times and as far as I can see, it’s identical to the video. Shouts are being created properly so my polymorphic association is setup correctly, but I must be missing something with rendering the partials. I’m on Rails 4.2.1, if that makes any difference for this specific issue.

@samjulien Thanks for the so post. It solved my problem

Did you fix this error already? Im having the same problem

Hey there folks, I have a two small problems with my application.

  1. My objects are not rendering, PhotoShout and TextShout I just get the reference to the object but not the content itself #<PhotoShout:0x007fe12a1f9e98> when I click on their show page

  2. I can’t manage to display the gravatar photo on the user I just get an empty reference. Does the actual user must already have a gravatar profile created? I just get E64c7d89f26bd1972efa854d13d7dd61?s=48

My image does not show up on the dashboard. It is just a “broken photo link” icon. If I click on it, it goes to the full size image just fine.

partial

<%= link_to image_tag(photo_shout.image.url(:shout)), photo_shout.image.url %>

model

class PhotoShout < ActiveRecord::Base
  has_attached_file :image, style: {
    shout: '200x200>'
  }
end

Anyone else have this issue?

That was it. Thanks!

Happy to help… glad you caught it before akimet flagged it as potential spam too lol

Hey guys! I’m at the end of video 2 for the ‘Shouter’ app, and I’m having a little trouble saving followed_users and followers to the db. I’ve tried to use Devise for authentication instead of Monbon, and believe the create method in my FollowingRelationships can controller is the issue. Anyone else tried to use Devise and find a work around? Here’s the link to my repos. I’ve tried to nut this one out myself but can’t find a solution!! GitHub - RuNpiXelruN/upcase_intermediate: Intermediate Upcase walk-through

I think this:

devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

needs to come before you declare associations in the User model