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

  • Home
  • SEARCH
  • 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 8686943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:59:34+00:00 2026-06-12T22:59:34+00:00

I have a two models, Items and Images. Under image model belongs_to :item and

  • 0

I have a two models, Items and Images. Under image model belongs_to :item and the item model has:many :images.

The image model has an item_id attribute.

Under the Items viewer I’m trying to display the images associated with each item. So for example I’d like to display image with item_id 1000 mapping onto Item with ID 1000.

I get a Couldn’t find Image with an ID error.

The Viewer looks like this:

<h1>Listing items - temporary testing page</h1>

<table>
  <tr>
    <th>Brand</th>
    <th>Item title</th>
    <th>Description</th>
    <th>Image link</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @items.each do |item| %>
  <tr>
    <td><%= item.brand %></td>
    <td><%= item.item_title %></td>
    <td><%= item.description %></td>
    <td><%= item.image_id %></td>
    <td><%= image_tag @findimages.small_img %></td>
    <td><%= link_to 'Show', item %></td>
    <td><%= link_to 'Edit', edit_item_path(item) %></td>
    <td><%= link_to 'Destroy', item, method: :delete, data: { confirm: 'Are you sure?' }     %></td>
  </tr>
<% end %>
</table>

<br />

<%= link_to 'New Item', new_item_path %>

The Items Controller like this:

class ItemsController < ApplicationController
  # GET /items
  # GET /items.json
  def index
    @items = Item.all(params[:id])
    @findimages = Image.find(params[:item_id])

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @items }
    end
  end
.
.
.

Help for a noob would be appreciated!

  • 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-06-12T22:59:35+00:00Added an answer on June 12, 2026 at 10:59 pm

    So it seems like there is no image with params[:item_id]

    1. use @findimages = Image.find(params[:item_id]) if params[:item_id]
    2. use validates_presence_of :item_id in image.rb
    3. Item.all(params[:id]) – wrong
      Item.find(params[:id]) of Item.all
    4. You are using :item_id – thats right. Next you shoud use has_one :image in item.rb and belongs_to :item in image.rb. so your code will looks like:

      def index  
        @items = Item.all
      

    and in view

    <td><%= image_tag item.image.small_img %></td>
    

    UPD: enter rails console and ensure that all images has an item_id by:

    Image.where(:item_id => nil)
    

    UPD2: Do not use pgadmin with rails, rails – best database administration tool.

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

Sidebar

Related Questions

I've got two models Category and Item. Category can have many items and item
I have two models, one is Group, the other Item. A group has many
I have two Models, Programme and Event, a programme has many events. I need
I've got two models: Item and Tag . Both have a name attribute. I
Support I have two models for items and categories, in a many-to-many relation class
I have a voting system with two models: Item(id, name) and Vote(id, item_id, user_id).
Currently i have two models: Rate and Item Rate is a model for voting,
I have two models, Item and ShopSection. They have a many-to-many relationship. @Entity(name =
I have a two models: class Category(models.Model): pass class Item(models.Model): cat = models.ForeignKey(Category) I
I have an STI-based model called Buyable, with two models Basket and Item. The

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.