Tag: 设计

在模型中访问devise current_user

您好我正在尝试访问模型中的current_user,以便使用find_or_create_by动态创建元素。 以下是我模型中的方法 def opponent_name=(name) self.opponent = Opponent.find_or_create_by_name_and_team_id(name,current_user.team_id) if name.present? end 但我得到的错误是 NameError in EventsController#create undefined local variable or method `current_user’ for #

将设计密码恢复限制为仅限某些用户

我的应用程序有一个预订系统,允许用户无需密码订阅。 但是尚未完成订阅的恶意用户(=还没有密码)可以按照密码恢复过程设置自己的密码并制止通常的订阅过程。 所以我希望Devise只为经过validation的用户(即完成订阅的用户)提供密码恢复。 如果未经validation的用户正在输入他的电子邮件以尝试获取新密码,我想向他显示“未找到电子邮件”错误,就好像他根本找不到。 我没有找到覆盖Devise的位置来添加这样的范围。 来自Recoverable 这个方法似乎适合但我无法自定义它: # Attempt to find a user by its email. If a record is found, send new # password instructions to it. If user is not found, returns a new user # with an email not found error. # Attributes must contain the user’s email def send_reset_password_instructions(attributes={}) recoverable = […]

用自定义create覆盖’Devise :: RegistrationsController’会产生NoMethodError

如果我以错误的方式解决这个问题,请告诉我。 我正在尝试在create方法中向User添加一些自定义属性,并在保存用户时调用我的Analytics方法。 我定义了一个新的控制器: class RegistrationsController after_sign_up_path_for(resource) else set_flash_message :notice, :”signed_up_but_#{resource.inactive_message}” if is_flashing_format? expire_data_after_sign_in! respond_with resource, :location => after_inactive_sign_up_path_for(resource) end else clean_up_passwords resource respond_with resource end end end 这个创建方法唯一不同的是我在保存和运行Analytics之后添加了referral_code和public_id 。 Analytics.identify( user_id: resource.id.to_s, traits: { email: resource.email }) 当我创建一个用户时,我正在获得 undefined method `is_flashing_format?’ for # 我不明白为什么这个方法没有被inheritance。 这甚至是修改设计或添加属性/添加分析的正确方法吗?

在密码重置期间,对Devise模型中的某些成员进行跳过validation

我的用户(设计)模型还有姓名,城市,国家,电话会员。 在创建注册页面 – 我validates_presence_of city, nation, phone, name, email, :on => :create _存在validates_presence_of city, nation, phone, name, email, :on => :create 在编辑注册页面中 – 我validates_presence_of city, nation, phone, name, :on => :update 现在,当我在forgot_password_page上设置一个新密码时,它会询问Devise::PasswordsController#update是否存在城市,国家,电话,姓名 我该如何处理选择性validation? 我猜它应该是这样的, validates_presence_of city, nation, phone, name, :on => :update, :if => :not_recovering_password def not_recovering_password # what goes here end

设计current_tenant在设计登录失败后重置为’public’

我在SAAS应用程序上使用Devise进行身份validation和Apartment for multi-tenancy支持。 登录失败后,将“重定向”设计到登录页面(Users :: SessionsController Apartment::Tenant.current ,之前在TenantElevator中间件中设置的Apartment::Tenant.current的值将恢复为其默认值“public”。 这种情况正在发生,因为Devise并未实际重定向到登录页面,而是使用新的机架环境调用FailureApp(呈现登录页面)并返回其响应。 新的机架应用程序没有TenantElevator中间件,因此租户未设置在机架应用程序中。 有谁知道如何解决这个问题? 也许我可以将TenantElevator中间件添加到Failure应用程序中?

将随机url参数传递给OmniAuth

我正在使用omniauth和devise,我想知道如何传递url params并访问它们。 这是一个链接示例: /accounts/auth/facebook?do_something_after_return=1现在我希望能够在回调中检索此do_something_after_return 。 我不在乎它是否在会话或其他地方保存。 问题是,我不知道在哪里可以拦截这个参数。 什么是链接/accounts/auth/facebook指向的控制器和操作? 路线什么都没告诉我,它根本就不存在。 我在路线中的所有内容都是/accounts/auth/:provider(.:format {:controller=>”accounts/omniauth_callbacks”, :action=>”passthru”}这是一个回调。

rails 3 + devise:如果注册表有错误,如何防止其他字段中的数据被删除?

我的设计注册表中有一个自定义字段(referral_code)。 还有一个自定义注册控制器(所以我可以在注册后重定向到自定义“检查您的电子邮件”页面)。 一切正常,除非新用户在显示错误消息时出错(例如密码/确认不匹配),它也会删除推荐代码字段。 当另一个字段(密码或电子邮件)向用户发送错误消息时,如何保持“填写”有效数据(推荐代码)?

设计 – Flash通知

使用带有Devise的rails,无论何时登录或注销设计都会在页面上发出Flash通知,从UI的角度来看这似乎是不必要的,它通常非常明显,对吧? 有没有办法在设计中为登录和注销关闭闪存通知? 谢谢

使用rspec的login_as首次测试失败

按照Devise How-To页面的说明,我正在尝试重建我的所有rspec测试以绕过用户登录过程。 有两种方法可用于此: 来自Devise的sign_in – 不能用于function测试(Capybara) 来自Warden的login_as (Devise是建立在它之上) 第一次射击的第一种方法(所有测试通行证)除了与Capybara的那些,所以我决定暂时离开它。 第二个给了我一些奇怪的结果 – 除第一个之外的所有传球(我作为文件中的第一个传球)。 当我只运行其中一个时它失败了。 我已经使用binding.pry进行了检查,但由于用户未登录并且重定向到登录页面而失败。 不知何故,第一次测试会触发一些使其余部分通过的东西。 我不知道这里发生了什么。 我之前使用的around钩子,但它的行为非常奇怪所以我把它改为before设置(同时它的工作速度要快得多,因为它只在乞讨时创建一个用户而不是每次测试)。 这就是现在的样子: require ‘spec_helper’ describe AlbumsController do let(:album) { create(:album) } before(:all) do @user = create :user end before(:each) do login_and_switch_schema @user end after(:all) do destroy_users_schema @user destroy_user @user end describe “GET #new” do before { get :new } […]

为没有STI的多个模型设计Omniauth

有没有办法为没有STI的多个模型配置Devise Omniauth? 我们有模特学生和教授,我们不想使用STI,但现在我们意识到Devise with Omniauth不适合多种模式。 .rvm/gems/ruby-1.9.3-p125/gems/devise-2.1.0/lib/devise/rails/routes.rb:384:in `devise_omniauth_callback’: Wrong OmniAuth configuration. If you are getting this exception, it means that either: (RuntimeError) 1) You are manually setting OmniAuth.config.path_prefix and it doesn’t match the Devise one 2) You are setting :omniauthable in more than one model 3) You changed your Devise routes/OmniAuth setting and haven’t restarted your […]