2013-10-20 86 views
0

好的,我已经安装了设计,我有我的注册页面,但是当我输入东西时,它告诉我它是空的,不能为空。我已验证存在和所有这些,所以我无法理解发生了什么。请参阅下面的表格,但我也注意到它闪烁电子邮件/密码不能空白两次...设计注册不拉场

让我知道你还可能需要什么。

色器件/ registrations.html.erb

会员注册

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> 
    <%= devise_error_messages! %> 



    <div><%= f.label :name %><br /> 
    <%= f.text_field :name %></div> 

    <div><%= f.label :profile_name %><br /> 
    <%= f.text_field :profile_name%></div> 

    <div><%= f.label :email %><br /> 
    <%= f.email_field :email %></div> 

    <div><%= f.label :password %><br /> 
    <%= f.password_field :password %></div> 

    <div><%= f.label :password_confirmation %><br /> 
    <%= f.password_field :password_confirmation%></div> 
<br /> 
    <div><%= f.submit "Sign up" %></div> 
<% end %> 

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

更新:日志显示以下

Parameters: {"utf8"=>"✓", "authenticity_token"=>"JGpbRxL9lPqYh34mcvXSVby7rl3NPwt/YyTrmgqcx9E=", "user"=>{"name"=>"", "profile_name"=>"", "email"=>"", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"} 
Unpermitted parameters: name, profile_name 

只是让我明白这个道理,为什么会说出,PROFILE_NAME是不允许的,这与attr_accessible有关吗?

解决方案。即使安装protected_attributes你仍然需要把

class ApplicationController < ActionController::Base 
before_filter :configure_permitted_parameters, if: :devise_controller? 
    # For APIs, you may want to use :null_session instead. 
    protect_from_forgery with: :exception 



    protected 

    def configure_permitted_parameters 
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :profile_name, :email, :password, :password_confirmation) } 
    end 
end 
+0

,请继续阅读并了解如何调试Rails应用程序:http://nofail.de/2013/10/debugging-rails-applications-in-development/ – phoet

+0

谢谢,我会读这个的。 –

+0

这有帮助,请参阅上面的日志。 –

回答

0

下,即使受保护的属性,看来你还需要将以下到您的应用程序控制器:

class ApplicationController < ActionController::Base 
before_filter :configure_permitted_parameters, if: :devise_controller? 
    # For APIs, you may want to use :null_session instead. 
    protect_from_forgery with: :exception 



    protected 

    def configure_permitted_parameters 
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :profile_name, :email, :password, :password_confirmation) } 
    end 
end 
0

你明确允许参数在你的控制器?

这除了configure_permitted_pa​​rameters

如需要。

def post_params 
    params.require(::sign_up).permit(:name, :profile_name, :email, :password) 
end