Tag: 设计

设计after_sign_in_path_for,但不是其他的

我真的在这里错过了一些东西。 我已经阅读了很多关于设计重定向的内容(对于大多数人来说似乎很难实现……)但在我的情况下我真的不明白。 有时我读到after__path_for(resource)应该在ApplicationController ,有时它被提到是在特定的控制器中,覆盖了设计控制器。 我宁愿在我的ApplicationController使用它们,因为它困扰我创建更多的控制器只是为了重定向,但如果最终不可能,我不会坚持…… 这是交易: 我在我的ApplicationController :(以及其他一些,但这对于该示例来说已经足够了) def after_update_path_for(user) flash[:notice] = ‘Successfully updated password’ edit_user_path(user) end def after_inactive_sign_up_path_for(user) flash[:notice] = ‘Welcome! Please follow the steps!’ me_new_path end def after_sign_up_path_for(user) flash[:notice] = ‘Welcome! Please follow the steps!’ me_new_path end def after_sign_in_path_for(user) if user.sign_in_count == 1 me_new_path else root_path end end 而疯狂的是,调用了after_sign_in_path_for ,而不是其他的。 就像用户注册时一样, if user.sign_in_count […]

如何为访客用户正确配置Devise + Cancan

在Rails 3.2应用程序中,我使用的是Devise + CanCan。 该应用程序以前仅限制登录用户的访问权限。 我正在添加一个Guest用户/能力,可以阅读该网站的某些部分。 我无法理解设置它的“正确”方法,特别是before_filter :authenticate!组合before_filter :authenticate! 控制器中需要load_and_authorize_resource 。 在努力实现这一目标时,我已将能力等级降至最低。 #Ability.rb class Ability include CanCan::Ability def initialize(user_or_admin) user_or_admin ||= User.new can :manage, :all end end 在无模型/静态页面Home控制器中 #home_controller.rb class HomeController < ApplicationController load_and_authorize_resource def index …some stuff end end 和 #application_controller.rb class ApplicationController < ActionController::Base protect_from_forgery before_filter :authenticate! …more stuff end 通过此设置,未登录的用户将被重定向到Devise登录页面。 如果我删除before_filter :authenticate! […]

rails3.2 + rspec + capybara1.0测试设计google-oauth2.0

我正在使用带有ruby1.9.2导轨的capybara 1.0 3.2这是我的测试: #spec/features/google_login_spec.rb require ‘spec_helper’ describe “the signin process”, type: :feature do before do puts user_omniauth_authorize_path(:google_oauth2) #/users/auth/google_oauth2 visit user_omniauth_authorize_path(:google_oauth2) end it {#somethings} end 但我有这个错误: Failures: 1) the signin process Failure/Error: visit user_omniauth_authorize_path(:google_oauth2) ActionController::RoutingError: No route matches [GET] “/o/oauth2/auth” # ./spec/features/google_login_spec.rb:9:in `block (2 levels) in ‘ 我的路线文件就是这个 #config/routes.rb Booking::Application.routes.draw do #https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview#using-omniauth-without-other-authentications devise_for :users , controllers: […]

Rails设计不适用于localhost上的rails 3.2.1

我按照本教程中讨论的每个步骤设计我的本地主机 – http://www.slideshare.net/wleeper/devise-and-rails upto page 8 of 22我希望同一个用户登录forms如第8页所述,但除此之外,我收到此错误 – 如果我保留在routes.rb文件中的注释, #matate’:controller(/:action(/:id))(:format)’ 然后这个消息标志 – 当我取消注释这一行时,它会显示此错误 – 关于rails的想法非常少,因为我来自PHP背景,但仍然在理论之前尝试一些实际测试,所以让我知道我究竟做错了什么。 我的routes.rb文件 – Prjmgt::Application.routes.draw do devise_for :users # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match ‘products/:id’ => ‘catalog#view’ # Keep in mind you can assign values […]

如何通过电子邮件validation用户?

我有一个rails应用程序,它使用devise进行身份validation。 当应用程序向用户发送任何通知时,为了查看通知或消息,我提供了一个链接到我的rails应用程序,该应用程序重定向到登录页面。 如何避免此登录过程,意味着我不希望通过输入电子邮件和密码要求用户登录,而只要用户点击该链接,用户就应该自动登录。

设计:新用户注册问题,PG :: ProtocolViolation。 Rails4,Postgres

我正在使用devise和omni-auth登录linkedin。 我将from_omniauth方法添加到Railscast中提到的用户模型: 这是代码: #Create a new user if does not exist def self.from_omniauth(auth) where(auth.slice(:provider, :uid)).first_or_create! do |user| user.provider = auth.provider user.uid = auth.uid user.email = auth.info.email end end Started GET “/users/auth/linkedin/callback?oauth_token=XXX” INFO — omniauth: (linkedin) Callback phase initiated. Processing by OmniauthCallbacksController#linkedin as HTML (0.4ms) BEGIN User Exists (0.6ms) SELECT 1 AS one FROM “users” WHERE […]

如何避免Devise从引擎内部进行身份validation?

我在我的主应用程序中使用Devise进行身份validation,并且我使用“http_basic_authenticate_with”构建了一个API(用于PABX),当我将before_action :authenticate_user!, except: [:method_name]到我的控制器时,它运行良好。 我这样做是因为except: [:method_name]不需要在Devise上记录用户会话,我只想对这些API控制器使用基本身份validation。 config/routes.rb (主应用程序) scope module: ‘api’ do scope module: ‘pabx’ do scope ‘/api/pabx’ do get ‘/accounts/phone_number/:phone_number’, to: ‘accounts#phone_number’ end end end controllers/api/pabx/accounts_controller.rb (主要应用) class Api::Pabx::AccountsController < ApplicationController http_basic_authenticate_with name: 'some_name', password: 'some_password' before_action :authenticate_user!, except: [:phone_number] skip_before_filter :verify_authenticity_token # POST api/pabx/accounts/phone_number.json def phone_number … end end 当我想在Engine中执行与API类似的操作时,问题就出现了。 当我尝试访问路由时,Devise似乎不允许在没有身份validation的情况下访问它,即使我正在使用before_action :authenticate_user!, except: […]

无法自动加载常量JWTBlacklist,预期/home/sourabh/dev/celebration/app/models/jwt_blacklist.rb来定义它(LoadError)

我的user.rb模型包含: class User < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :lockable, :timeoutable, :omniauthable, :jwt_authenticatable, jwt_revocation_strategy: JWTBlacklist def send_devise_notification(notification, *args) devise_mailer.send(notification, self, *args).deliver_later end end 我正在使用devise-jwt gem来登录我的rails api。 我的JWTBlacklist.rb模型包含: class JwtBlacklist < ApplicationRecord include Devise::JWT::RevocationStrategies::Blacklist self.table_name = 'jwt_blacklist' end

设计:在特定情况下是否可以不发送确认电子邮件?

实际上我正在使用设计登录和注册并且工作正常,它会发送一封非常好的确认电子邮件。 但我需要在特定情况下发送确认电子邮件。 我在URL中传递用户类型,并代表我要设置邮件。 我有两种类型的用户,一种是确认他们的帐户,他们的自我重置用户无法确认他们的帐户只有管理员可以批准他们的帐户。 我已经覆盖了create方法 def create super if params[:type]==’xyz @user.skip_confirmation_notification! end end 但它在两种情况下都会发送邮件。 请告诉我哪里错了。

如果有Devise和Rails的问题?

我只想创建一个对象的人,例如注册表来查看某些内容=,但是却在努力用Devise定义所有内容 这是代码: 提前致谢 PS我正在使用cancan,但这对我想要显示页面的节目页面没有帮助。