我对RoR社区比较陌生,我试图通过最初的Devise或Omniauth-Facebook为每个用户提供 Profiles . 在实施身份验证系统之后,我有点不知所措 .

我希望你们中的一些人可以在注册/登录重定向到显示登录用户名称的个人页面后给我一点点领导和一些推动 . 我已经尝试为 Profiles 和观点创建新模型,但没有运气 .

我的最终目标是让每个用户的 Profiles 页面显示用户上传的姓名,图片和一些文字......

这是我的代码行:

user.rb用户模型

class User < ActiveRecord::Base
  has_many :authentications
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :omniauthable,
         :recoverable, :rememberable, :trackable, :validatable,
         :omniauth_providers => [:facebook]

  attr_accessible :email, :password, :password_confirmation

  def self.from_omniauth(auth)
    where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.name = auth.info.name
      user.email = auth.info.email
      user.oauth_token = auth.credentials.token
      user.oauth_expires_at = Time.at(auth.credentials.expires_at)
      user.save!
    end
  end

  def self.new_with_session(params, session)
    if session["devise.user_attributes"]
      new(session["devise.user_attributes"], without_protection: true ) do |user|
        user.attributes = params
        user.valid?
      end
    else
      super
    end
  end

  def password_required?
    super && provider.blank?
  end

  def email_required?
    super && provider.blank?
  end
end

class OmniauthCallbacksController <Devise :: OmniauthCallbacksController

def all user = User.from_omniauth(request.env [“omniauth.auth”])

if user.persisted?
  sign_in_and_redirect user, notice: "Signed in!"
else
  session["devise.user_attributes"] = user.attributes
  redirect_to new_user_registration_url
end

结束alias_method:facebook,:all end

ApplicationController的

class ApplicationController < ActionController::Base

  protect_from_forgery with: :exception

end

的routes.rb

Rails.application.routes.draw do

  devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" } 
  root            'static_pages#home'
  get 'help' =>   'static_pages#help'
  get 'about' =>  'static_pages#about'
  get 'contact' => 'static_pages#contact'

end

最后是宝石文件

source 'https://rubygems.org'
ruby   '2.1.4'

gem 'rails',                   '4.2.0.beta4'
gem 'bcrypt',                  '3.1.7'
gem 'faker',                   '1.4.2'
gem 'carrierwave',             '0.10.0'
gem 'mini_magick',             '3.8.0'
gem 'fog',                     '1.23.0'
gem 'will_paginate',           '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bootstrap-sass',          '3.2.0.0'
gem 'sass-rails',              '5.0.0.beta1'
gem 'uglifier',                '2.5.3'
gem 'coffee-rails',            '4.0.1'
gem 'jquery-rails',            '4.0.0.beta2'
gem 'turbolinks',              '2.3.0'
gem 'jbuilder',                '2.2.3'
gem 'rails-html-sanitizer',    '1.0.1'
gem 'sdoc',                    '0.4.0', group: :doc
gem 'devise', github: 'plataformatec/devise'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'omniauth-linkedin'
gem 'figaro'
gem 'protected_attributes'

我是否需要执行rails generate devise:控制器以在登录/注册时自定义重定向?或者是否可以制作单独的控制器和模型来管理所有这些?

先感谢您!