我的应用程序运行在两个不同的数据库上,我使用应用程序逻辑来处理它们。
用户模型位于外部db上,我只在default_role类上记录id。
因此,在索引模板中,我从远程获取帐户,对于其中的每个,我必须查询我的表以打印一些不可变的信息,并且我希望给出在表中更改角色的可能性。
索引信息=远程表信息(名称、姓氏、ecc) +我的表信息(角色)
使用best_in_place编辑用户的role_id字段。
问题是我的索引周期@操作符,来自外部购买我需要改变角色,这是我这边的!
- @operators.each do |ope| #cycle users
%tr
%td
- user = User.find_by_bay_id(ope.account_id)
- df = DefaultRole.find_by_operator_id(user.id)
= best_in_place [:admin, df], :role_id, :type => :select, :collection => [[1, 'admin'], [2, 'coordinator'], [3, 'operator'], [4, 'base']]我在控制器上的更新:
respond_to :html, :json
def index
@operators = some logic from model where I get all the users
end
def update
@df = DefaultRole.find(params[:id])
@df.update_attributes(params[:default_role])
respond_with [:admin, @df]
end但它甚至没有在控制器中调用我的更新方法。它通常检查集合标签,允许我更改它,但它不允许我提交。
我做错了什么?
编辑
我的浏览器没有捕捉到任何请求。
发布于 2013-01-24 16:20:21
发布于 2013-01-24 10:40:05
JSON使用Best_in_place调用来更新内容。在这种情况下,控制器中应该有respond_to json语句,如下所示:
def update
@df = DefaultRole.find(params[:id])
respond_to do |format|
if @df.update_attributes(params[:default_role])
format.html { redirect_to root_path, notice: 'Role was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @df.errors, status: :unprocessable_entity }
end
end我觉得奇怪的是,在您的视图中包含变量规范,它们属于控制器(- user = User.find_by_bay_id(ope.account_id) - df = DefaultRole.find_by_operator_id(user.id) )。
https://stackoverflow.com/questions/14498801
复制相似问题