0

我一直在关注这个站点上的教程来创建一个 jQuery CRUD 表单。

我有一个Artist具有单一验证的模型来检查display_name字段的唯一性。

当发布创建操作时,WEBrick 日志的相关部分显示如下:

Started POST "/artists" for 10.1.1.1 at 2012-10-07 13:50:00 +1300
Processing by ArtistsController#create as JS
  Parameters: { (ommited parts for brevity) , "artist"=>{"display_name"=>"Banksy"}, "commit"=> "Create Artist"}
  User Load (0.6ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Artist Load (0.5ms)  SELECT `artists`.* FROM `artists`
   (0.4ms)  BEGIN
  Artist Exists (1.4ms)  SELECT 1 AS one FROM `artists` WHERE `artists`.`display_name` IS NULL LIMIT 1
   (0.5ms)  ROLLBACK
  Rendered artists/create.js.erb (0.5ms)
Completed 200 OK in 71ms (Views: 55.5ms | ActiveRecord: 3.4ms)

我很难理解当很明显在传递的参数中display_name设置为非空字符串时,但在运行的验证查询中,它正在检查它是否为空的实例。

4

1 回答 1

0

“POST /artists”控制器动作的源代码是什么?

创建操作必须params适当地访问。在这种情况下,类似于:

def create
  @artist = Artist.create(params[:artist])
  # then render or redirect
end

你的行动Artist.create是否正确params

于 2012-10-07T01:10:20.473 回答