我当前的应用程序结构如下所示:
示例控制器如下所示:
class Api::V1::RegisterController < Api::V1::ApiController
def create
@user = ::V1::User.new(user_params)
@user.email_address = params[:email_address]
@user.age_verification = params[:age_verification]
@user.remote_addr = request.env['REMOTE_ADDR']
@user.web_browser = browser.name.to_s + "(" + browser.version.to_s + ")"
@user.operating_system = browser.platform.to_s
if @user.save
head status: 201
else
render_bad_request(@user.errors.messages)
end
end
private
def user_params
params.permit(:email_address, :remote_addr, :web_browser, :operating_system, :age_verification)
end
end
示例模型如下所示:
class V1::User < ActiveRecord::Base
validates_presence_of :remote_addr, :web_browser,
:operating_system, :age_verification, :email_address
validates :email_address, uniqueness: { case_sensitive: false },
email_format: { check_mx: true }
end
我的主要问题是为什么我被迫::V1
在我的模特面前使用?有没有更好的方法解决这个问题还是我错过了什么?