【问题标题】:Customining devise creating action定制设计创建动作
【发布时间】:2013-02-13 07:42:40
【问题描述】:

在我的控制器中创建我有以下代码

def create
    params[:user].merge!(verified: true)
    super
  end

在我的表单上,我有名称为 tos_agreement 的复选框。如果我的 tos_agreement 值在 params != '1' 中,我如何强制设计不要在 super 中保存资源,而是通过向@user.errors 添加错误来渲染?

我不能使用模型方法来实现这样的复选框,所以我必须通过控制器来处理它而不重写设计的超级方法

【问题讨论】:

    标签: ruby-on-rails ruby devise


    【解决方案1】:

    您可以使用 rails 中提供的validates_acceptance_of。看看here

    【讨论】:

    • 正如我所说,我无法在模型中进行任何验证,只有控制器可以更改
    • 然后像这样redirect_to root_path, :flash => {:error => "Please accept T&C"} and return if false
    • 在这种情况下,我将丢失实例 var @user、错误、表单数据等中的所有内容
    • 试图这样做,但这是我在控制台 Processing by UsersController#index as */* [Devise] Could not find devise mapping for path "/users". Maybe you forgot to wrap your route inside the scope block? For example: devise_scope :user do match "/some/route" => "some_devise_controller" end Completed 404 Not Found in 3ms AbstractController::ActionNotFound - Could not find devise mapping for path "/users". Maybe you forgot to wrap your route inside the scope block? For example: devise_scope :user do match "/some/route" => "some_devise_controller" end 中得到的
    猜你喜欢
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 2013-08-25
    • 2013-12-22
    相关资源
    最近更新 更多