use of halper form_for
-
I'm confused... using a helper.
form_for
:<%= form_for @foods do |f| %> <% end %>
in contrast
@foods
Like:def index @foods = Food.all end
migration is defined as:
create_table "foods", force: :cascade do |t| t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false end
The model is defined as:
class Food < ActiveRecord::Base end
so the tracks (gem 'rails', '4.2.6') on the shirts ( ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux] ) are issued:
undefined method `to_key' for "#Food: ActiveRecord_Relation:0x00002af6f98" Did you mean? to_query to_ary
What's wrong?
-
If the shape is emitted in the route of the appropriate method
index
the mistake is that instead of creating one new model@food = Food.new
or search for an existing record
@food = Food.find(params[:id])
You extract all the records that match the models.
Food
@foods = Food.all
You're not making an object.
Food
The one that's waiting forchopper.from_for
a collectionActiveRecord::Relation
which cannot be processed. ♪from_for
Only one object should be transferred.