This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/intermediate-part-2
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:
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.
-
My objects are not rendering,
PhotoShout
andTextShout
I just get the reference to the object but not the content itself#<PhotoShout:0x007fe12a1f9e98>
when I click on their show page -
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