没有使用.build或update_attributes保存到数据库的属性

时间:2012-11-16 17:46:38

标签: sql ruby-on-rails

我可以在帖子消息中看到所有正确的参数,但它们没有保存到数据库中。这是控制器代码:

  def create
    @ask = current_user.asks.build(params[:ask])
    @ask.save
  end

def update
    @ask = current_user.asks.find_by_id(params[:id])
    next_step = @ask.check_change(params[:ask])
    if next_step == "ask2"
      @ask.update_attributes(params[:ask])
      ask2
      flash[:notice] = "Description added"
    elsif next_step == "ask3"
      @ask.update_attributes(params[:ask])
      ask3
      flash[:notice] = "Helper and public added"
    elsif next_step == "ask4"
      @ask.update_attributes(params[:ask])
      ask4
      flash[:notice] = "Category added"
    else
      @ask.update_attributes(params[:ask])
      flash[:notice] = "Not sure what to do"
    end

这是SQL:

Started POST "/asks" for 127.0.0.1 at 2012-11-16 12:39:22 -0500
Processing by AsksController#create as JS
  Parameters: {"utf8"=>"√", "authenticity_token"=>"n10gHRjvRpu4z40z+jDSTyOdNJrIm
NQdkPgNeS3XM14=", "ask"=>{"description"=>"new ask description is going here"}, "
commit"=>"Add a need"}
  ←[1m←[35mUser Load (0.0ms)←[0m  SELECT "users".* FROM "users" WHERE "users"."i
d" = ? LIMIT 1  [["id", 12]]
  ←[1m←[36m (0.0ms)←[0m  ←[1mbegin transaction←[0m
  ←[1m←[35mSQL (1.0ms)←[0m  INSERT INTO "asks" ("category", "created_at", "date_
done", "date_followed_up", "description", "done", "followed_up", "helper", "publ
ic", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["categ
ory", nil], ["created_at", Fri, 16 Nov 2012 17:39:22 UTC +00:00], ["date_done",
nil], ["date_followed_up", nil], ["description", nil], ["done", false], ["follow
ed_up", false], ["helper", nil], ["public", false], ["updated_at", Fri, 16 Nov 2
012 17:39:22 UTC +00:00], ["user_id", 12]]
  ←[1m←[36m (7.0ms)←[0m  ←[1mcommit transaction←[0m
  Rendered shared/_error_messages.html.erb (0.0ms)
  Rendered asks/_ask2.html.erb (5.0ms)
  Rendered layouts/_debug.html.erb (1.0ms)
  Rendered asks/create.js.erb (10.0ms)
Completed 200 OK in 38ms (Views: 25.0ms | ActiveRecord: 8.0ms)

我确信我在控制器中做错了什么,但我已经尝试了一些排列而无法解决这个问题。

0 个答案:

没有答案