【问题标题】:undefined method `openid_identifier' for #<AccountSession: no credentials provided>#<AccountSession: 未提供凭据> 的未定义方法“openid_identifier”
【发布时间】:2010-06-15 12:05:21
【问题描述】:

我正在尝试在我的应用程序中获取 authlogic 和 openid。到目前为止,它非常不愉快。我已尝试关注有关该主题的 Railscast,但似乎没有任何 gem 或插件有效。

在阅读了previous error 之后,我最终安装了this open-id plugin(在该页面底部提到)。现在我收到错误:

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

我还不能确定这是否是一种改进。

观点:

%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 :openid_identifier

控制器:

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    

已安装宝石:

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

如果听到只是我在做一些愚蠢的事情,那将是个好消息。太晚了,我已经看这个太久了,所以它很有可能。

谢谢!

【问题讨论】:

    标签: ruby-on-rails openid authlogic


    【解决方案1】:

    您是否阅读过该插件的文档 (http://github.com/binarylogic/authlogic_openid)?听起来您忘记创建/运行以下迁移:

        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
    

    【讨论】:

    • 不确定,但看起来您在 @account_session 上调用 openid_identifier 但如果您查看迁移,它 openid_identifier 是 :users 的一种方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-09
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 1970-01-01
    • 2015-11-22
    相关资源
    最近更新 更多