开发者

undefined method `openid_identifier' for #<AccountSession: no credentials provided>

开发者 https://www.devze.com 2023-01-03 07:29 出处:网络
I am trying to get authlogic and openid happening in my app. So far its been seriously unpleasant. I have tried to follow the Railscasts on the topic but none of the gems or plugins seem to work.

I am trying to get authlogic and openid happening in my app. So far its been seriously unpleasant. I have tried to follow the Railscasts on the topic but none of the gems or plugins seem to work.

A after reading about a previous error I ended up installing this open-id plugin (mentioned at the bottom of that page). Now I am getting the error:

ActionView::TemplateError (undefined method `openid_identifier' for #<AccountSession: no credentials provided>) on line #13 of app/views/account_sessions/new.html.haml:

I can't decide if this is an improvement yet.

The view:

%h3
  Login:
- form_for(@account_session) do |f|
   = f.error_messages
  %p
    =t 'account.login'
    =f.text_field :login
  %p
    =t 'account.password'
    =f.password_field :password
  %p
    =t 'account.openid_identifier'
    =f.text_field :openi开发者_开发知识库d_identifier

The controller:

class AccountSessionsController < ApplicationController

      def new
        @account_session = AccountSession.new
      end

      def create
        @account_session = AccountSession.new(params[:account_session])

       @account_session.save do |result|
         if result
          flash[:notice] = I18n.t 'session.login_success'
          redirect_to root_url
        else
          render :action => "new" 
        end
       end
      end

      def destroy
        @Account_session = AccountSession.find
        @Account_session.destroy
        flash[:notice] = I18n.t('session.logout_message')
        redirect_to root_url
      end
    end    

gems installed:

authlogic (2.1.5, 2.1.4, 2.1.3)
authlogic-oid (1.0.4)
ruby-openid (2.1.8, 2.1.7)

It would be great news to hear it was just me doing something dumb. Its late and I've been looking at this too long so its quite possible.

Thanks!


Have you read the docs (http://github.com/binarylogic/authlogic_openid) for the plugin? It sounds like you forgot to create/run the following migration:

    class AddUsersOpenidField < ActiveRecord::Migration
    def self.up
      add_column :users, :openid_identifier, :string
      add_index :users, :openid_identifier

      change_column :users, :login, :string, :default => nil, :null => true
      change_column :users, :crypted_password, :string, :default => nil, :null => true
      change_column :users, :password_salt, :string, :default => nil, :null => true
    end

    def self.down
      remove_column :users, :openid_identifier

      [:login, :crypted_password, :password_salt].each do |field|
        User.all(:conditions => "#{field} is NULL").each { |user| user.update_attribute(field, "") if user.send(field).nil? }
        change_column :users, field, :string, :default => "", :null => false
      end
    end
  end
0

精彩评论

暂无评论...
验证码 换一张
取 消