Take the 2-minute tour ×

Ok this is my first app in rails so hopefully this is a simple problem.

Here is my object:

- !ruby/object:ProductImage
attributes_cache: {}

This works:

<%= image_form.text_field :product_id %>

But I get undefined method `image_id' for:

<%= image_form.text_field :image_id %>

I just don't get it...

Cheers for any help on this.

This is the actual partial:

<div class="image">
  <% new_or_existing = product_image.new_record? ? 'new' : 'existing' %>
  <% prefix = "product[#{new_or_existing}_product_image_attributes][]" %>
  <% fields_for prefix, product_image do |i| -%>
    <div class="input select">
      <%= i.text_field :image_id %>
      <%= link_to_function "remove", "$(this).up('.image').remove()" %>
  <% end -%>

P.S a text field is being used just as an example

share|improve this question
Ok the problem was in my helper method, the object I was using was from another method as I copied/pasted it and did not double check –  mynameisrufus Jan 30 '10 at 3:40

2 Answers 2

Can you post the entire form? I have a hunch that maybe you did:

<% form_for :image do |image_form| %>

instead of:

<% form_for :product_image do |product_image_form| %>

Of course, I'd rethink displaying a form where people are manually entering id values in order to join an image to a product, but I understand you're in learning mode right now.

share|improve this answer

ID fields should not be text_fields, they should be checkboxes or drop-down select boxes. Why would your use know what the Rails ID is?

share|improve this answer

Your Answer


