我有一个配置文件 Controller 。但是我想使用User模型在users表中保存一些字段。那么如何将用户模型加载到概要文件 Controller 中?
最佳答案
模型是独立的实体,您可以从任何 Controller 调用它。
There can be a model without a controller and vice-versa.
对于您的问题,请在下面举一个例子
class ProfileController < ApplicationController
def some_method
@user = User.find(params[:user_id])
if @user.update_attributes(params[:user])
// some action
else
// some action
end
end
end
关于ruby-on-rails - 如何在RoR中的不同 Controller 中使用模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3005002/