I am trying to make a connection with facebook and ruby on rails using the omniauth-facebook, but when I try to make a connection it sends me an error of "no implicit conversion of Symbol into Integer" , would be very helpful if you can tell me where I am making the mistake this is the code I am using:
in the initializers folder I created an omniauth.rb file:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'xxxxface_book_idxxxxx', 'xxxsecret_id_facebookxxxxxx'
end
I create a route in routes.rb:
get 'auth/:provider/callback', to: 'sessions#create'
get 'auth/failure', to: redirect('/')
get 'signout', to: 'sessions#destroy', as: 'signout'
followed by a controller sessions_controller.rb:
def create
user = User.from_omniauth("omniauth.auth")
session[:user_id] = user.id
redirect_to root_url
end
def destroy
session[:user_id] = nil
redirect_to root_url
end
Then I create a model called user.rb:
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
Then in application_controller.rb:
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_user
Then I add in application.html.erb:
<% 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 %>
but when I click on the link it sends me the error:
Any ideas where I may be making the mistake ??? I will really appreciate if you can help me with this.