簡體   English   中英

Devise的強項不是將字段輸入列入白名單

[英]Devise's strong parameter isn't whitelisting a field input

看來我添加的自定義輸入字段未列入白名單(提交時顯示空白驗證錯誤)。

這是控制器:

class AccountsController < ApplicationController

  before_filter :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) << :name
  end
end

它基本上是Devise文檔中的復制內容,但根本不起作用(即,沒有將我的自定義輸入字段列入白名單)。

更新:
形式如下:

<h2>Sign up</h2>

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">

    <%= f.input :name %>
    <%= f.input :email %>
    <%= f.input :password %>
    <%= f.input :password_confirmation %>
  </div>

  <div class="form-actions">
    <%= f.button :submit, "Sign up" %>
  </div>
<% end %>

<%= render "accounts/shared/links" %>

嘗試這個:

devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:name) }

試試這個,希望對您有所幫助,並解決您的問題。

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.

  before_filter :configure_permitted_parameters, if: :devise_controller?

  def configure_permitted_parameters
   devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:firstname, :lastname, :email, :password, :password_confirmation) } #here you can permit custom fields. 
  end

  protect_from_forgery with: :exception
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM