更新 1: 更新された問題の説明
問題文
私は Devise を使用しており、登録ユーザーに他の人をサイトに招待するオプションを提供しています。その場合は、ActionMailer を使用して、トークン認証 (例: ) を使用して URL 経由で招待状を送信しますhttp://localhost:3000/payments?auth_token=SsdLxnQ9Eemf6mNsFDfu
。これらの新しいユーザーには属性non_registered = 1
があり、認証が必要な一部の資料にアクセスできますが、他の機能は登録されていないため使用できません。Users
サイトを使用した後にパスワードを作成して完全に登録されたユーザーになるオプションを自分のサイトに表示したいのですが、アカウント情報を編集してアカウントを作成するときに、現在のパスワードを空白にすることはできませんというエラー メッセージが表示されます。新しいパスワード。
初歩的な質問だと思いますが、初心者です。RoR を愛し、発生するすべての問題は学習の機会です。私のコードの何が問題なのですか?
私の進歩
私は周りを見回していくつかの関連リンクを見つけましたが、私が取り組んでいる特定のユースケースに対処しているようには見えません:
- https://groups.google.com/forum/#!msg/plataformatec-devise/1eV4WzH6myc/IiBA4un46RQJ
- https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password
- Ruby on Rails、Devise gem。パスワードが空白のときに現在のパスワードを削除するには?
- Rails 3 - Devise:登録を編集するときに「current_password」をスキップする方法は?
- Devise の現在のパスワード要件を停止する
コントローラーをオーバーライドしRegistrations
、DeviseEdit
ビューをカスタマイズしてcurrent_password
フィールドを削除しました。:current_password
また、User
モデルにattr_accessible
とを追加しましたが、attr_accessor
これが必要かどうかはよくわかりません。とにかく、パスワードを更新しようとすると、 現在のパスワードを空白にすることはできませんというエラーが引き続き表示されます。
マイコード
app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def update
if params[:user][:not_registered] == "1"
params[:user].delete("current_password")
end
successfully_updated = super
if successfully_updated
params[:user][:not_registered] == "0"
end
end
def new
super
end
def create
super
end
def edit
super
end
def cancel
super
end
def destroy
super
end
end
app/views/devise/registrations/edit.html.erb
<% if current_user.not_registered != 1 %>
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<% else %>
<h2>Sign up</h2>
<% end %>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div><%= f.label :password %><br />
<%= f.password_field :password, :autocomplete => "off" %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<% if current_user.not_registered != 1 %>
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %></div>
<% end %>
<div class="field">
<%= f.hidden_field :not_registered, :value => current_user.not_registered %>
</div>
<% if current_user.not_registered != 1 %>
<div><%= f.submit "Update" %></div>
<% else %>
<div><%= f.submit "Sign up" %></div>
<% end %>
<% end %>
アプリ/モデル/user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :token_authenticatable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
attr_accessible :email, :password, :password_confirmation,
:remember_me, :not_registered, :pay_method, :pay_desc, :email_instructions, :current_password
attr_accessor :current_password
has_many :payments
end