在RoR中提交之前,可以通过调用模型方法获取属性的值。下面是一种常见的方法:
class User < ApplicationRecord
# ...
def get_name
self.name
end
# ...
end
class UsersController < ApplicationController
def create
@user = User.new(user_params)
# 获取姓名属性值
name = @user.get_name
# 在这里进行提交等操作
# ...
end
# ...
end
这样,你就可以在提交之前获取模型方法中属性的值了。
注:这里仅为示例,并不涉及具体的云计算相关内容。
领取专属 10元无门槛券
手把手带您无忧上云