6

にマッチしていない私はdevise_token_authバージョン0.1.38を使用して、既存のユーザーに署名しようとしているが、私は、ライブラリのsessions_controllerIndexError: string not matchedを打っています。devise_token_auth&Railsの5 - はIndexError:文字列が

IndexError (string not matched): 

devise_token_auth (0.1.38) app/controllers/devise_token_auth/sessions_controller.rb:37:in `[]=' 
devise_token_auth (0.1.38) app/controllers/devise_token_auth/sessions_controller.rb:37:in `create' 
actionpack (5.0.0) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action' 
actionpack (5.0.0) lib/abstract_controller/base.rb:188:in `process_action' 
actionpack (5.0.0) lib/action_controller/metal/rendering.rb:30:in `process_action' 
actionpack (5.0.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action' 

sessions_controllerから関連するコードは次のとおりです。

if @resource and valid_params?(field, q_value) and @resource.valid_password?(resource_params[:password]) and ([email protected]_to?(:active_for_authentication?) or @resource.active_for_authentication?) 
    # create client id 
    @client_id = SecureRandom.urlsafe_base64(nil, false) 
    @token  = SecureRandom.urlsafe_base64(nil, false) 

    # !! Next line is line 37 with the error !! 
    @resource.tokens[@client_id] = { 
     token: BCrypt::Password.create(@token), 
     expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i 
    } 
    @resource.save 

    sign_in(:user, @resource, store: false, bypass: false) 

それは私がtokens列に不正なデータを作成している可能性が高いですので、私は既存のプロジェクトにdevise_token_authを追加しました。私はのコードを模倣することを含め、私の既存のユーザーにtoken jsonをデフォルト設定するさまざまな方法を試しました。

add_column :users, :tokens, :json, null: false, default: {} 

User.reset_column_information 
client_id = SecureRandom.urlsafe_base64(nil, false) 
token  = SecureRandom.urlsafe_base64(nil, false) 

User.find_each do |user| 
    user.uid = user.email 
    user.provider = 'email' 
    user.tokens[client_id] = { 
     token: BCrypt::Password.create(token), 
     expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i 
    } 
    user.save! 
end 

これについては、issue #101に記載されていますが、具体的な解決策はありませんでした。私がどこに間違っているのか?

+0

私にとって、これは私がHeroku上で私のレールアプリを実行するときに起こるようです。ローカルインスタンスにはこの問題はありません。 Postgresのバージョン(9.6.2)がHerokuのバージョン(9.6.4)とローカルに異なることに気付きました。それが問題を引き起こしているかどうかわからない –

答えて

4

私はtokensnilに設定する必要があることが判明し、次にそれを設定してくれます。私は答えを見つけたthis devise issue.

def change 
    add_column :users, :provider, :string, null: false, default: "email" 
    add_column :users, :uid, :string, null: false, default: "" 
    add_column :users, :tokens, :text 

    reversible do |direction| 
    direction.up do 
     User.find_each do |user| 
     user.uid = user.email 
     user.tokens = nil 
     user.save! 
     end 
    end 
    end 

    add_index :users, [:uid, :provider], unique: true 
end 
関連する問題