2014-04-18 107 views
0

当我尝试编辑用户信息时,点击“更新”后没有任何反应,除了最后显示真实性标记的网址。该日志显示一个未经许可的参数错误,看起来像这样:无法编辑用户配置文件

Unpermitted parameters: utf8, _method, authenticity_token, user, commit, format 

我改变了色器件路线添加omniauth注册等,以及单独的编辑视图定制色器件控制器。 的路线:

devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}, 
       controllers: {omniauth_callbacks: "omniauth_callbacks"} 

devise_scope :user do 
get "/info" => "registrations#info" 
end 

这里是定制色器件控制器:

class RegistrationsController < Devise::RegistrationsController 
def info 
    @user = current_user 
    if @user 
     render :info 
    else 
     redirect_to root_path 
    end 
    end 

    def update 
    @user = User.find(params[:id]) 


    @user.update_without_password(devise_parameter_sanitizer.for(:account_update)) 
redirect_to user_path(current_user) 

end 
protected 

def after_sign_up_path_for(resource) 
    '/info' 
    end 
end 

,这里是编辑观点:

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put}) do |f| %> 

<%= f.input :name %> 
<%= f.input :email %> 

<% end %> 
+0

请更新有关服务器日志包括'params'哈希和'未经许可params'警告的问题。 –

+0

更新,谢谢。那是你想要的吗? – user2759575

+0

让我们来聊聊聊聊http://chat.stackoverflow.com/rooms/48530/ror –

回答

1

由于每个聊天会话,OP有两个forms为:

<form class="form-horizontal"> 
<form accept-charset="UTF-8" action="/users" class="simple_form user" enctype="multipart/form-data" id="edit_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="om7WhULk2OPgMGwjbTz5h79BqUlkr4lF9aRVDaOxUhs=" /></div> 

建议删除<form class="form-horizontal">和类添加到如下现有simple_form_for

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put}, :class =>"form-horizontal") do |f| %> 

此外,更新用户记录没有密码,更改如下更新操作:

def update 
    # For Rails 4 
    account_update_params = devise_parameter_sanitizer.sanitize(:account_update) 

    # required for settings form to submit when password is left blank 
    if account_update_params[:password].blank? 
     account_update_params.delete("password") 
     account_update_params.delete("password_confirmation") 
    end 

    @user = User.find(current_user.id) 
    if @user.update_attributes(account_update_params) 
     set_flash_message :notice, :updated 
     # Sign in the user bypassing validation in case his password changed 
     sign_in @user, :bypass => true 
     redirect_to user_path(current_user) 
    else 
     render "edit" 
    end 
    end 

UPDATE

您目前的通话将“将处理由Devise :: RegistrationsController#更新为HTML” Devise::RegistrationsController,而不是你的RegistrationsController 更新routes.rb如下:

devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}, 
controllers: {omniauth_callbacks: "omniauth_callbacks", registrations: :registrations}