NoMethodError в AuthenticationsController # create | омниаут + разработка - PullRequest
1 голос
/ 16 мая 2011

NoMethodError в AuthenticationsController # create

неопределенный метод `user 'для # / аутентификации: 0x00000105c7b1f8 \

Я выдергиваю волосы ... Я скачал пример приложения с Railscasts, и оно работает ... У меня есть то, что похоже на последнюю ошибку.

Я пытаюсь проследить за Railscasts, чтобы добавить это в мое приложение, которое работает / работало в противном случае - http://railscasts.com/episodes/236-omniauth-part-2

Кажется, что в основном это происходит - в таблице полномочий есть запись ..

Я не дошел до шага, когда страница запрашивает электронное письмо, потому что у него его нет.

Я уверен, что это очень просто - вот некоторые фрагменты:

Контроллер:

class AuthenticationsController < ApplicationController

  def create
    omniauth = request.env["omniauth.auth"]
    authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
    if authentication
      flash[:notice] = "Signed in successfully."
      sign_in_and_redirect(:user, authentication.user)
    elsif current_user
      current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
      flash[:notice] = "Authentication successful."
      redirect_to authentications_url
    else
      @user = User.new
      @user.apply_omniauth(omniauth)
      if @user.save
        flash[:notice] = "Signed in successfully."
        sign_in_and_redirect(:user, user)
      else
        session[:omniauth] = omniauth.except('extra')
        redirect_to new_user_registration_url
      end

    end
  end

end

разработка пользовательской модели:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable, :lockable and :timeoutable
  has_many :authentications

  devise :database_authenticatable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  #attr_accessible :email, :password, :password_confirmation, :remember_me

  def apply_omniauth(omniauth)
    self.email = omniauth['user_info']['email'] if email.blank?
    authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
  end

  def password_required?
    (authentications.empty? || !password.blank?) && super
  end

end

некоторые маршруты. Rb:

  resources :authentications
  match '/auth/:provider/callback' => 'authentications#create'

  get "search/show"

  #devise_for :users
  devise_for :users, :controllers => {:registrations => 'registrations'}

1 Ответ

0 голосов
/ 17 мая 2011

В sign_in_and_redirect должно быть @user (: пользователь, пользователь).Не user.

...