Для авторизации в приложении я использую логин через фейсбук, через гем 'omniauth-facebook'. Но застрял на данный момент, как получить список друзей, которые тоже используют мое приложение (вошли в систему), и отобразить результат на отдельной странице. И поделиться своими ресурсами в приложении (в образце закладок)
Мой гемфайл
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
gem 'rails', '~> 6.0.0'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5'
gem 'webpacker', '~> 4.0'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
gem 'bootsnap', '>= 1.4.2', require: false
gem 'omniauth-facebook'
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'dotenv-rails'
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Модель пользователя
class User < ApplicationRecord
has_many :bookmarks, dependent: :destroy
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth['provider']
user.uid = auth['uid']
if auth['info']
user.name = auth['info']['name'] || ""
user.email = auth['info']['email'] || ""
end
end
end
end
Контроллер сеансов
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
user = User.where(:provider => auth['provider'],
:uid => auth['uid']).first || User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to root_url, :notice => "Signed in!"
end
def new
redirect_to '/auth/facebook'
end
def destroy
reset_session
redirect_to root_url, notice => 'Signed out'
end
end
Контроллер закладок
class BookmarksController < ApplicationController
before_action :authenticate
before_action :set_bookmark, only: [:show, :edit, :update, :destroy, :bookmark_owner]
before_action :bookmark_owner, only: [:show, :edit, :update, :destroy]
def index
@bookmarks = current_user.bookmarks
end
def show
end
def new
@bookmark = current_user.bookmarks.build
end
def edit
end
def create
@bookmark = current_user.bookmarks.build(bookmark_params)
respond_to do |format|
if @bookmark.save
format.html { redirect_to @bookmark, notice: 'Bookmark was successfully created.' }
format.json { render :show, status: :created, location: @bookmark }
else
format.html { render :new }
format.json { render json: @bookmark.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @bookmark.update(bookmark_params)
format.html { redirect_to @bookmark, notice: 'Bookmark was successfully updated.' }
format.json { render :show, status: :ok, location: @bookmark }
else
format.html { render :edit }
format.json { render json: @bookmark.errors, status: :unprocessable_entity }
end
end
end
def destroy
@bookmark.destroy
respond_to do |format|
format.html { redirect_to bookmarks_url, notice: 'Bookmark was successfully destroyed.' }
format.json { head :no_content }
end
end
def bookmark_owner
unless @bookmark.user_id == current_user.id
flash[:notice] = 'Access denied as you are not owner'
redirect_to bookmarks_path
end
end
private
def set_bookmark
@bookmark = Bookmark.find(params[:id])
end
def bookmark_params
params.fetch(:bookmark, {}).permit(:name, :url)
end
end
ApplicationController
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
helper_method :current_user
def authenticate
redirect_to :login unless user_signed_in?
end
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
def user_signed_in?
!!current_user
end
end
Буду признателен за помощь: что можно использовать для этих целей.