小编use*_*798的帖子

什么是Rails关联的更新方法?

这很简单,我觉得无法在任何地方找到任何有关这方面的信息,包括API文档和Rails源代码:

我有一个:belongs_to关联,我已经开始理解你在控制器中调用的正常模型方法,当你没有关联时,与你做的时候略有不同.

例如,我的创建控制器操作的关联工作正常:

@user = current_user
@building = Building.new(params[:building])

respond_to do |format|
   if @user.buildings.create(params[:building])
# et cetera
Run Code Online (Sandbox Code Playgroud)

但我找不到有关更新如何工作的文档:

@user = current_user
@building = @user.buildings.find(params[:id])

respond_to do |format|
  if @user.buildings.update(params[:building])
# et cetera
Run Code Online (Sandbox Code Playgroud)

使用update方法给出错误"错误的参数数量(1 for 2)",我无法弄清楚应该发送什么参数.

ruby activerecord ruby-on-rails associations

5
推荐指数
1
解决办法
6352
查看次数

标签 统计

activerecord ×1

associations ×1

ruby ×1

ruby-on-rails ×1