Note that there are some explanatory texts on larger screens.

plurals
  1. POPaperclip loads image on one page, but doesn't display on another. "Missing.png"
    primarykey
    data
    text
    <p>I'm following the railscast for PaperClip and have ImageMagick installed. I followed his video and code as well. The uploaded image is displayed perfectly in one view, but is missing on another view. I am essentially trying to get the same image uploaded to display on both pages instead of just one. </p> <p><img src="https://i.stack.imgur.com/hki99.png" alt="enter image description here"></p> <p>I get the following when I inspect the image element on chrome:</p> <pre><code>&lt;img alt="Missing" src="/photos/medium/missing.png?1316405973"&gt; </code></pre> <p>Here's my form:</p> <pre><code>&lt;%= form_for @micropost, :html =&gt; { :multipart =&gt; true } do |f| %&gt; &lt;%= render 'shared/error_messages', :object =&gt; f.object %&gt; &lt;div class="field"&gt; &lt;%= f.text_area :content %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit "Submit" %&gt; &lt;/div&gt; &lt;div class="photo"&gt; &lt;%= f.file_field :photo %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Here's my "micropost" model since I've been following the rails tutorial</p> <pre><code> class Micropost &lt; ActiveRecord::Base attr_accessible :content, :photo, :photo_file_name, :photo_content_type, :photo_file_size, :photo_updated_at belongs_to :user has_attached_file :photo, :url =&gt; "/assets/products/:id/:style/:basename.:extension", :path =&gt; ":rails_root/public/assets/products/:id/:style/:basename.:extension" validates_attachment_presence :photo validates_attachment_size :photo, :less_than =&gt; 5.megabytes validates_attachment_content_type :photo, :content_type =&gt; ['image/jpeg', 'image/png' end </code></pre> <p>And here's my _micropost.html.erb file with the image_tag on line 4. </p> <p>****Notice that I removed the @ instance variable before the word micropost. This is not following the example because I get a No Method Error: undefined method `photo' for nil:NilClass when I do make it into an instance variable. After removal, I am able to get an image to display.**</p> <pre><code> &lt;tr&gt; &lt;td class="micropost"&gt; &lt;span class="content"&gt;&lt;%= micropost.content %&gt;&lt;/span&gt; &lt;%= image_tag micropost.photo.url(:medium) %&gt; #### This is the code added ######## &lt;span class="timestamp"&gt; .... .... ... &lt;/td&gt; &lt;% end %&gt; &lt;/tr&gt; </code></pre> <p><strong>However, on the feed page, I do use the @micropost instance variable otherwise I get a NameError in Pages#home, undefined local variable or method `micropost' for Class. Making it an instance variable at least shows something on the page. This is the view with the missing image.</strong> feed_item.html.erb</p> <pre><code> &lt;tr&gt; &lt;td class="gravatar"&gt; ... ... &lt;/span&gt; &lt;span class="content"&gt;&lt;%= feed_item.content %&gt;&lt;/span&gt; &lt;%= image_tag @micropost.photo.url(:medium) %&gt; #### inserted code## &lt;span class="timestamp"&gt; Posted &lt;%= time_ago_in_words(feed_item.created_at) %&gt; ago. .... .... &lt;% end %&gt; &lt;/tr&gt; </code></pre> <p>****EDIT** </p> <p>Here's my controller code:</p> <pre><code>class MicropostsController &lt; ApplicationController before_filter :authenticate, :only =&gt; [:create, :destroy] before_filter :authorized_user, :only =&gt; :destroy def create @micropost = current_user.microposts.build(params[:micropost]) if @micropost.save flash[:success] = "Blurb posted!" redirect_to root_path else @feed_items = [] render 'pages/home' end end </code></pre> <p>Anyone have a clue to what's wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload