ruby on rails - Getting undefined 'image' errors when using paperclip for image upload? -


I'm trying to use a paperclip to show the image of a user in the post index, but I'm getting A "missing" link in its place.

I am using Devise for authentication. Paperclip for more image uploads Which is disappointing because it works for me sometime, but occaisonaly brings me such troublesome errors. Thanks for the help, I have been stuck here for some days.

Here is my post index: (Error has been thrown on the 8th line)

  & lt;% @. Posted in | & Gt%; & Lt; Ul & gt; & Lt; Li & gt; & Lt; Div class = "well large" & gt; & Lt; Div class = "media" & gt; & Lt; One class = "pull-left" href = "#" & gt; & Lt;% = image_tag current_user.image.url (: thumb)% & gt; & Lt; / A & gt; & Lt; Div class = "media-body" & gt; & Lt; H4 square = "media-title" & gt; & Lt;% = post.title% & gt; & Lt; / H4 & gt; & Lt;% = post.content% & gt; & Lt ;! - Nested Media Object - & gt; & Lt; Div class = "media" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt;% end% & gt; & Lt; / Li & gt;   

  class user & lt; ActiveRecord :: Base has has_many: Post has_attached_file: image ,: styles = & gt; {: Thumb = & gt; "100x100 & gt;" } ,: Default_url = & gt; "/images/:style/missing.png" validates_attachment_content_type: image ,: content_type = & gt; /Eimage\/.**Z/ # Include modules to develop by default Other: are available: #: Confirmation, lockout, timeline and: Universal plan: Database_ authorized, registerable, recoverable, memorable,: Trackable, validity   

Post.rb

  class post   

My posts from my post controller are here:

  private def post_params params.require (: post) .permit (: title, content) end    

It is quite clear from the error that Getting you Check out this line:

  & lt; One class = "pull-left" href = "#" & gt; & Lt;% = image_tag current_user.image.url (: thumb)% & gt; & Lt; / A & gt;   

Your current_user has zero here, and so you get:

undefined method `Image to Zero: NilClass

This means that you are requesting this method and there is no user login while loading this view i.e. no user session has been done. Please read your PostController : before_filter: authenticate_user! Try entering a check in or sign in before accessing the PostsController indexing method.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -