Rails build,关联关系为什么不生效呢

fahchen · 2012年04月28日 · 最后由 congteng 回复于 2012年05月14日 · 2583 次阅读
class OrderController < ApplicationController
  def create
    @order = current_user.orders.build(params[:order])
    @order.save
  end
end

User 和 Order 已经关联好了的,并且在 console 下这样写能够把 current_user 和@order关联上,但是通过页面新建就不能关联上(@order能成功写入数据库了) 如果把上面的 controller 中的 build 换成 create 就能建立关联并写入数据库

看看log信息

需要 登录 后方可回复, 如果你还没有账号请 注册新账号