设计用户无法编辑

时间:2014-12-14 03:36:02

标签: ruby-on-rails devise simple-form basic-authentication

我有一个使用Devise进行用户身份验证的Rails应用程序。我非常确定Devise编辑用户功能以前有用,但出于某种原因,编辑/更新不再起作用。当我点击"更新"时,页面只会在表单上刷新。它还会显示"请查看以下问题:"即使我已正确输入所有内容。

然而,取消帐户功能完美无缺。问题可能是网址路径吗?如果是这样,为什么取消帐户工作,而更新不是?我确实将用户模型嵌套在另一个模型中,但我尝试了url路径上的变体,但没有一个有效。

以下是Devise生成的表单页面并使用simple_form:

.col-md-5.col-md-offset-2
  %h2
    Edit #{resource_name.to_s.humanize}
  = simple_form_for(resource, as: resource_name, url: registration_path(resource_name)    , html: { method: :put }) do |f|
    = f.error_notification
    .form-inputs
      = f.input :email, required: true, autofocus: true
      - if devise_mapping.confirmable? && resource.pending_reconfirmation?
        %p
          Currently waiting confirmation for: #{resource.unconfirmed_email}
      = f.input :password, autocomplete: "off", hint: "leave it blank if you don't     want to change it", required: false
      = f.input :password_confirmation, required: false
      = f.input :current_password, hint: "we need your current password to confirm     your changes", required: true
    .form-actions
      = f.button :submit, "Update"
  %h3 Cancel my account
  %p
    Unhappy? #{link_to "Cancel my account", registration_path(resource_name), data: {     confirm: "Are you sure?" }, method: :delete}
  = link_to "Back", root_path

更新

这是来自development.log的打印输出:

Started PUT "/users" for 127.0.0.1 at 2014-12-14 00:05:07 -0500
Processing by Users::RegistrationsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Zhtv8rbmwIDuZO7Tv/0db7tSIGfGUEW56fqPKzkgQSo=", "user"=>{"email"=>"test3@test3.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Update"}
  [1m[36mUser Load (0.3ms)[0m  [1mSELECT  `users`.* FROM `users`  WHERE `users`.`id` = 16  ORDER BY `users`.`id` ASC LIMIT 1[0m
  [1m[35mUser Load (0.2ms)[0m  SELECT  `users`.* FROM `users`  WHERE `users`.`id` = 16 LIMIT 1
  [1m[36m (0.2ms)[0m  [1mBEGIN[0m
  [1m[35m (0.1ms)[0m  ROLLBACK
  Rendered devise/registrations/edit.html.haml within layouts/application (4.3ms)
  Rendered common/_login.html.haml (0.5ms)
Completed 200 OK in 328ms (Views: 175.1ms | ActiveRecord: 0.7ms)

这是我的routes.rb文件。我有两次列出用户。

devise_for :users

root 'welcome#index'

resources :wedding_checklists do
  resources :users
  resources :checklist_items
end

1 个答案:

答案 0 :(得分:1)

在我看来,错误已经发生但未显示。请在表单中添加<%= devise_error_messages! %>,告诉我打印出的错误。