Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 195937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:43:29+00:00 2026-05-11T16:43:29+00:00

I’m getting up to speed on rails and ran into an odd problem. I’m

  • 0

I’m getting up to speed on rails and ran into an odd problem. I’m rendering some images from the database (Image models attached to another model, Plants). I’m having some trouble when attempting to do it via a partial. I’ve got show.html.erb

 <fieldset class="fieldset">
      <legend>Images</legend>
      <%=  unless @plant.images.blank? then
                for image in @plant.images
                     debugger 
                     render :partial => 'show_image', :object => image 
                end
           else
                "This plant has no images to display."
           end
      %>
 </fieldset>

And the partial _show_image.html.erb:

 <div class="image_container">
      <% debugger %>
      <img src="<%= url_for(:action => 'picture', :id => object.id) %>"/> 
      <p class='image_caption'><%= object.comment %></p> 
 </div>

When this is rendered it just renders a “#” for each image, rather than the actual image. It seems to be just rendering the object as a string, as in the source I get:

 <fieldset class="fieldset">
      <legend>Images</legend>
      #<Image:0x242c910>
 </fieldset>

When running through the debugger locally:

 /Users/*****/dev/plantmanager/app/views/plants/show.html.erb:54
 debugger
 (rdb:241) image
 #<Image id: 40, comment: "Test", name: "Ixia.gif", content_type: "image/gif", data: "GIF89a2\0002\000####$\205\233\tI\250\"x\224\b?\206\031d|ju####\v\031###\247\bI\257G\222\232\222\227\263\262...", plant_id: 55, thumbnail: nil> 
 (rdb:221) @plant
 #<Plant id: 55, name: "Test", description: "Test", created_at: "2009-05-07 07:19:44", updated_at: "2009-05-07 07:19:44", planted: "2009-05-07 00:00:00", sprouted: "2009-05-15 00:00:00", plant_type_id: 1, finished: "2009-05-27 00:00:00">
 (rdb:221) @plant.images
 [#<Image id: 40, comment: "Test", name: "Ixia.gif", content_type: "image/gif", data: "GIF89a2\0002\000####$\205\233\tI\250\"x\224\b?\206\031d|ju####\v\031###\247\bI\257G\222\232\222\227\263\262...", plant_id: 55, thumbnail: nil>]
 (rdb:221) continue
 /Users/*****/dev/plantmanager/app/views/plants/_show_image.html.erb:2
 <% debugger %>
 (rdb:221) object
 #<Image id: 40, comment: "Test", name: "Ixia.gif", content_type: "image/gif", data: "GIF89a2\0002\000####$\205\233\tI\250\"x\224\b?\206\031d|ju####\v\031###\247\bI\257G\222\232\222\227\263\262...", plant_id: 55, thumbnail: nil>
 (rdb:221) object.id
 40
 (rdb:221) object.comment
 "Test"
 (rdb:221) continue

Here are my models [snipped a bit]:

class Plant < ActiveRecord::Base
     has_many :images

     validates_presence_of :name
     validates_presence_of :plant_type_id
     validates_associated :images


     after_update :save_images

     def image_attributes=(image_attributes)
          image_attributes.each do |attributes|
               # TODO: Probably handle validation in the image model?
               if attributes[:id].blank?
                   unless attributes[:uploaded_picture].blank?
                        tmpImg = images.build()
                        tmpImg.uploaded_picture=attributes[:uploaded_picture]
                        tmpImg.comment = attributes[:comment] 
                   end
               else
                   img = images.detect { |i| i.id == attributes[:id].to_i }
                   img.attributes = attributes
                end
           end
      end


      def save_images
           images.each do |i|
                if i.should_destroy?
                     i.destroy
                else
                     i.save(false)
                end
           end 
      end
 end

 class Image < ActiveRecord::Base 
      validates_format_of :content_type, 
                          :with => /^image/, 
                          :message => "--- you can only upload pictures" 

      attr_accessor :should_destroy

      def should_destroy?
           should_destroy.to_i == 1
      end

      def uploaded_picture=(picture_field)
           self.name = base_part_of(picture_field.original_filename) 
           self.content_type = picture_field.content_type.chomp 
           self.data = picture_field.read
           #image = MiniMagick::Image.from_blob self.data
           #self.thumbnail = resize_and_crop(image, 100).to_blob
      end 

      def base_part_of(file_name) 
           File.basename(file_name).gsub(/[^\w._-]/, '') 
      end
 end 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:43:29+00:00Added an answer on May 11, 2026 at 4:43 pm

    Try this instead:

    <%  unless @plant.images.blank?
                    for image in @plant.images
    %>
                         <%= render :partial => 'show_image', :object => image %>
                    <% end
               else %>
                    This plant has no images to display.
               <% end %>
    

    Sorry about the formatting, but you get the idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.