0
我想用表格來創建新的類別。
在new.html.erb一切都很好:
<%= form_for @cat do |f| %>
<%= f.label :description %>
<%= f.text_field :description %>
<br>
<%= f.label :position %>
<%= f.text_field :position %>
<%= f.submit %>
<% end %>
但 「提交」 後,按引發ArgumentError在CategoriesController#創建升高(未知鍵:說明)。 http://prntscr.com/1fijdk
categories_controller.rb
class CategoriesController < ApplicationController
def index
@categories = Category.all
end
def new
@cat = Category.new
end
def create
@category = Category.find(params[:category])
redirect_to :categories
end
end
category.rb
class Category < ActiveRecord::Base
has_many :items
end
schema.rb
ActiveRecord::Schema.define(version: 20130715035836) do
create_table "categories", force: true do |t|
t.string "description"
t.integer "position"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "items", force: true do |t|
t.string "name"
t.float "price"
t.text "description"
t.integer "category_id"
t.datetime "created_at"
t.datetime "updated_at"
end
end
在Rails 3中一切都很好,但是在Rails 4中沒有生成attr_accessible,我有點困惑。問題在哪裏?