0

我对新生成的脚手架有一个烦人的问题。一切都会很好地运行,但是虽然我可以输入数据,但每次我尝试保存时,他都会成功提交 nil。适用于所有领域。

看起来像这样:

Started POST "/spraches" for 127.0.0.1 at 2012-08-26 23:34:03 +0200
Processing by SprachesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"nMf1+rBegI9BKoSAekzq8iLPQPAHpiiPk2DlmhEQxsQ=", "sprache"=>{"name"=>"23", "level"=>"23", "zertifikat"=>"124", "zertifikat_anders"=>"213", "zertifikat_note"=>"f23"}, "commit"=>"Create Sprache"}
  [1m[36m (1.0ms)[0m  [1mBEGIN[0m
  [1m[35mSQL (29.0ms)[0m  INSERT INTO "spraches" ("created_at", "level", "name", "updated_at", "zertifikat", "zertifikat_anders", "zertifikat_note") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["created_at", Sun, 26 Aug 2012 21:34:03 UTC +00:00], ["level", nil], ["name", nil], ["updated_at", Sun, 26 Aug 2012 21:34:03 UTC +00:00], ["zertifikat", nil], ["zertifikat_anders", nil], ["zertifikat_note", nil]]
  [1m[36m (1.0ms)[0m  [1mCOMMIT[0m
Redirected to http://localhost:3000/spraches/1
Completed 302 Found in 35ms (ActiveRecord: 31.0ms)

在详细查看代码后,原因对我来说变得显而易见:我用德语(Sprache -> Language)命名我的表,Rails 试图将其设置为复数。但是,控制器只有单数形式。

@sprach = Sprache.new(params[:sprach])

我在参数中添加了一个“e”以匹配传入的代码。作品。

4

1 回答 1

0

在详细查看代码后,原因对我来说变得显而易见:我将表命名为 inGerman (Sprache -> Language)并且 Rails 尝试将其设置为plural. 但是,控制器仅在singular表单中具有它。

@sprach = Sprache.new(params[:sprach])

"e"在参数中添加了一个以匹配传入的代码。作品。

于 2012-08-26T21:45:21.527 回答