我正在尝试为链接创建一个简单的嵌套输入字段。
我的 konkurrancer 模型:
accepts_nested_attributes_for :link
has_one :link
我的链接模型:
class Link < ActiveRecord::Base
belongs_to :konkurrancer
end
我的 konkurrencer 表格:
<%= simple_form_for [@konkurrancer] do |f| %>
<%= f.simple_fields_for :link do |d| %>
<%= d.input :link %>
<% end %>
<%= f.button :submit, :value => 'Opret konkurrence' %>
<% end %>
当我提交表单时,我收到此错误:
ActiveRecord::UnknownAttributeError in Admin/konkurrancersController#create
unknown attribute: links
参数:
{"utf8"=>"✓",
"authenticity_token"=>"MACFM37hX4S6XA9vryn7gtfl21PvcaPBSiKDI8mfurg=",
"konkurrancer"=>{"name"=>"sadasd",
"links"=>{"link"=>"http://localhost:3000/konkurrancers/new"},
"commit"=>"Opret konkurrence"}
我的控制器:
def create
@konkurrancer = Konkurrancer.new(params[:konkurrancer])
respond_to do |format|
if @konkurrancer.save
format.html { redirect_to(:admin_konkurrancers, :notice => 'Konkurrancer was successfully created.') }
format.xml { render :xml => :admin_konkurrancers, :status => :created, :location => @konkurrancer }
else
format.html { render :action => "new" }
format.xml { render :xml => @konkurrancer.errors, :status => :unprocessable_entity }
end
end
end
我的 Rails 控制台日志:
Started POST "/admin/konkurrancers" for 127.0.0.1 at 2011-04-27 01:40:50 +0200
Processing by Admin::KonkurrancersController#create as HTML
Parameters: {"utf8"=>"Ô£ô", "authenticity_token"=>"MACFM37hX4S6XA9vryn7gtfl21P
vcaPBSiKDI8mfurg=", "konkurrancer"=>{"name"=>"sadasd", "banner2"=>"asdasdas", "t
racking"=>"asdasdd", "vaerdi"=>"3434", "tid"=>"2 min", "tag_tokens"=>"2", "links
"=>{"link"=>"http://localhost:3000/admin/konkurrancers/new"}, "kategori_id"=>"10
", "form"=>"Nyhedsbrev", "partner"=>"Orville", "udtraekkes(1i)"=>"2011", "udtrae
kkes(3i)"=>"27", "udtraekkes(2i)"=>"4", "note"=>""}, "commit"=>"Opret konkurrenc
e"}
←[1m←[36mKonkurrancer Load (1.0ms)←[0m ←[1mSELECT `konkurrancers`.* FROM `kon
kurrancers`←[0m
←[1m←[35mCACHE (0.0ms)←[0m SELECT `konkurrancers`.* FROM `konkurrancers`
←[1m←[36mCACHE (0.0ms)←[0m ←[1mSELECT `konkurrancers`.* FROM `konkurrancers`←
[0m
←[1m←[35mAdmin Load (1.0ms)←[0m SELECT `admins`.* FROM `admins` WHERE (`admin
s`.`id` = 1) LIMIT 1
←[1m←[36mTag Load (1.0ms)←[0m ←[1mSELECT `tags`.* FROM `tags` WHERE (`tags`.`
id` = 2) LIMIT 1←[0m
←[1m←[35mSQL (1.0ms)←[0m BEGIN
←[1m←[36mSQL (0.0ms)←[0m ←[1mCOMMIT←[0m
Completed in 314ms
ActiveRecord::UnknownAttributeError (unknown attribute: links):
app/controllers/admin/konkurrancers_controller.rb:48:in `new'
app/controllers/admin/konkurrancers_controller.rb:48:in `create'
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_trace.erb (2.0ms)
←[1m←[35mKonkurrancer Load (0.0ms)←[0m SELECT `konkurrancers`.* FROM `konkurr
ancers` LIMIT 15 OFFSET 0
←[1m←[36mSQL (4.0ms)←[0m ←[1mSHOW TABLES←[0m
←[1m←[35mSQL (4.0ms)←[0m SHOW TABLES
←[1m←[36mSQL (4.0ms)←[0m ←[1mSHOW TABLES←[0m
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_request_and_response.erb (266.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/diagnostics.erb within rescues/layout (324.0ms)