Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble rendering images uploaded with CarrierWave
    text
    copied!<p>I'm building a basic Rails 4 application, and seem to have hit a frustrating snag. I've been following the <a href="http://railscasts.com/episodes/253-carrierwave-file-uploads" rel="nofollow">CarrierWave Railscast</a>, and while I'm able to get images to show up on /image/show.html.erb, I've had some difficulties with getting any of the images I've uploaded to display in the gallery each image is associated with. </p> <p>The strange thing is, there aren't any errors logged. The page loads without any Rails errors coming up in the page or the terminal; the only way I know something is wrong is that the div that images are supposed to appear in doesn't show up at all.</p> <p>I'm really stumped about this. If you look, the .images div in the show action for galleries renders, but absolutely none of the sub-elements render at all. What am I doing wrong?</p> <p><a href="https://github.com/DeadSuperHero/DeadSuperHero" rel="nofollow">Source code here</a></p> <p><strong>app/models/image.rb</strong> </p> <pre><code>class Image &lt; ActiveRecord::Base belongs_to :gallery mount_uploader :image, ImageUploader end </code></pre> <p><strong>app/models/gallery.rb</strong></p> <pre><code>class Gallery &lt; ActiveRecord::Base has_many :images end </code></pre> <p><strong>app/uploaders/image_uploader.rb</strong></p> <pre><code>class ImageUploader &lt; CarrierWave::Uploader::Base include CarrierWave::RMagick storage :file def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end version :thumb do process :resize_to_limit =&gt; [200, 200] end end </code></pre> <p><strong>apps/views/images/show.html.erb</strong><br> Below, we can see that images can be rendered without issue, as this is a view for their own respective controller.</p> <pre><code>&lt;p&gt; &lt;strong&gt;Title:&lt;/strong&gt; &lt;%= @image.title %&gt; &lt;/p&gt; &lt;p&gt; &lt;strong&gt;Description:&lt;/strong&gt; &lt;%= @image.description %&gt; &lt;/p&gt; &lt;p&gt; &lt;strong&gt;Image:&lt;/strong&gt; &lt;%= image_tag @image.image_url.to_s %&gt; &lt;/p&gt; </code></pre> <p><strong>/apps/views/galleries/show.html.erb</strong><br> This is where everything gets tricky. First off, no matter what I change within the images div, everything within it seems to come up blank regardless. I've tried changing the "for image in @gallery.images" bit several times, but to no avail.</p> <pre><code>&lt;div id="images"&gt; &lt;% for image in @gallery.images %&gt; &lt;div class="image"&gt; &lt;%= image_tag image.image_url(:thumb) %&gt; &lt;%= image.description %&gt; &lt;div class="name"&gt;&lt;%= image.title %&gt;&lt;/div&gt; &lt;div class="actions"&gt; &lt;%= link_to "edit", edit_image_path(image) %&gt; | &lt;%= link_to "remove", image, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt; &lt;/div&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt; &lt;p&gt; &lt;%= link_to "Add a Painting", new_image_path(:gallery_id =&gt; @gallery) %&gt; | &lt;%= link_to "Remove Gallery", @gallery, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt; | &lt;%= link_to "View Galleries", galleries_path %&gt; &lt;/p&gt; </code></pre>
 

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