This project is archived and is in readonly mode.

#4155 ✓resolved
Conrad Taylor

ActiveResource generates an error for a form_for attribute

Reported by Conrad Taylor | March 11th, 2010 @ 10:56 PM

Hi, ActiveResource generates the following error when I attempt to create a new resource instance:

ActionView::TemplateError (undefined method `name' for #<Product:0x1034edcd0>) on line #7 of app/views/products/new.html.erb:
4:   <%= f.error_messages %>
5:   <p>
6:     <%= f.label :name %><br />
7:     <%= f.text_field :name %>

I have the following product resource model and associated view:

/app/models/product.rb:

class Product < ActiveResource::Base
  self.site = "http://api.example.com:3001/"
end

/app/views/products/new.html.erb:

<h1>New product</h1>

<% form_for(@product) do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :price %><br />
    <%= f.text_field :price %>
  </p>
  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>

<%= link_to 'Back', products_path %>

Next, the relevant controller code.

/app/controllers/products_controller.rb:


...

  # GET /products/new
  # GET /products/new.xml
  def new

    @product = Product.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @product }
    end

  end

...

My hardware and software details are as follows:

$ ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
$ rails -v Rails 2.3.5
$ gem -v 1.3.6

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages