0
  <div class="field">
    <%= f.label :name %><br>
    <%= f.text_area :name %>
  </div>

  <div class="field">
    <%= f.label :content %><br>
    <%= f.text_area :content, :cols =>20, :rows => 20 %>
  </div>

  <div class="actions">
    <%= f.submit %>
  </div>

<%= f.text_area :name %> line is causing the error. When I remove it, it works fine.

Above lines are for when creating a new status...when I click on the "new status" button, error shows up. please help. Thank you!

  • 4
    We need to see the 'form' line, the error, the exact line the error references, the model schema, and the 'new' action from the relevant controller. – Philip Hallstrom Feb 01 '14 at 07:18
  • is there any specific cause to define `<%= f.text_area :name %>` twice, in single `form`? – rony36 Feb 01 '14 at 07:58
  • I suspect your form would be better suited to a text_field for `:name` anyway. Do you actually have a `name` attribute in your model? – Jon Feb 01 '14 at 09:40
  • It's not defined twice, I think he just made a mistake when posting the question. – nktokyo Feb 01 '14 at 10:14
  • Is "name" permitted in the controller? Rails 4 has new ways of restricting access to fields. – nktokyo Feb 01 '14 at 10:20

1 Answers1

0

The no method error either means you don't have a name attribute defined in the table, or you don't have the name method in your model


attr_accessor

You have to remember that Rails is basically a bunch of classes all strung together; and models use the attr_accessor ruby method to create the attributes of your objects

The ways you could fix your error are:

  1. Ensure you have a name column (attribute) in your DB
  2. Ensure your model is retrieving said name attribute (you're not using .select())
  3. Use attr_accessor to create a name attribute
  4. Use alias_attribute to create the name attribute from another

Without seeing your other code, this should help:

#app/models/model.rb
Class Model < ActiveRecord::Base
    attr_accessor :name
end
Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147