未定义的方法`openid_identifier'用于#<accountsession:no =“”credentials =“”“provided =”“> </accountsession:>

时间:2010-06-15 12:05:22

标签: ruby-on-rails openid authlogic

我正在尝试在我的应用中发生authlogic和openid。到目前为止,它一直非常不愉快。我试图按照主题关注Railscasts,但没有任何宝石或插件似乎有效。

在阅读了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)

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

谢谢!

1 个答案:

答案 0 :(得分:0)

您是否阅读过该插件的文档(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