こんにちは、私は現在 Railscast 360 に従って、Facebook 認証を Web アプリケーションに追加しています。このエラーが発生し始めるまで、すべてうまくいっていました:
"SessionsController#create の NoMethodError
未定義のメソッド `name=' for #"
app/models/user.rb:6:in
block in from_omniauth' app/models/user.rb:3:in
タップ' app/models/user.rb:3:infrom_omniauth' app/controllers/sessions_controller.rb:3:in
create'
このWebサイトでいくつかの異なる回答を見てきましたが、それらの多くは、Facebookを機能させようとしているTwitter認証用のようです.
Facebook Developers でアプリを作成し、レール キャストのチュートリアルを完全に実行しました。これについて何か助けていただければ幸いです。
これまでの私のコードは
ユーザー.rb:
class User < ActiveRecord::Base
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
end
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
rescue ActiveRecord::RecordNotFound
end
helper_method :current_user
end
session_controller.rb
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
redirect_to root_url
end
def destroy
session[:user_id] = nil
redirect_to root_url
end
end
これは私のapplication.html.erb内の私のコードです:
<div id="user_nav">
<% if current_user %>
Signed in as <strong><%= current_user.name %></strong>!
<%= link_to "Sign out", signout_path, id: "sign_out" %>
<% else %>
<%= link_to "Sign in with Facebook", "/auth/facebook", id: "sign_in" %>
<% end %>
本当に助けていただければ幸いです。
ありがとう