Tag: 设计

设计自动登录用户

当我注册一个用户,但还没有确认设置时(即将来会被注释掉),它会自动登录用户吗? 我需要sign_up来签署用户,但不签署他,它需要重定向到登录页面,我如何注册不登录用户?

在Active Admin中切换公寓租户

这是我上一篇文章的扩展: 活跃的管理员和公寓gem 我以为我有这个工作,但我被卡住了。 我在公共架构中有一个Company模型作为租户模型和各个租户的Locations 。 这是我的Active Admin location.rb文件: ActiveAdmin.register Location do #Apartment::Tenant.switch!(‘abc’) controller do #Apartment::Tenant.switch!(‘abc’) before_filter do Apartment::Tenant.switch!(‘abc’) skip_authorization skip_policy_scope end end end skip_authorization skip_policy_scope来自我仍然使用AA的一些Pundit问题。 正如您所看到的,我尝试在几个地方添加Apartment::Tenant.switch 。 在控制器块内是我可以让它工作的唯一地方。 当我加载Locations索引页面时,它工作正常,我看到我的租户位置。 问题是,如果我回到仪表板或其他页面并返回位置并致电Apartment::Tenant.switch我会被踢回AA登录屏幕,我无法重新登录。我必须手动进入AA注销路径以强制注销。 这很奇怪,不知道如何解决这个问题。 日志显示不多。 我打算在这里添加一些逻辑菜单下拉菜单以设置会话变量等,然后在需要时让资源页面调用Apartment::Tenant.switch ,但这是一个截止的截止现在。 不知道它是Devise,Pundit,Apartment,Active Admin还是组合。 UPDATE 一些进步 – 试图添加开关的输出! 调用记录器调试并“解决”问题。 如果我将开关调用设置为变量,它也会消失: logger.debug “Apartment Switch: #{Apartment::Tenant.switch!(‘abc’).inspect}” new_tenant = Apartment::Tenant.switch!(‘abc’) 更新2 我之前的更新是错误的 – 问题仍然存在。 我把它缩小到了Devise。 第二个switch! […]

如何覆盖设计可锁定模块

我试图覆盖Lockable模块以支持devise-token-auth,但它没有覆盖。 我到处搜索,一无所获。 我想我错过了什么,但我不知道是什么。 任何帮助,将不胜感激 module Lockable extends Devise::Models::Lockable def valid_for_authentication? # My code end end

在rails中调用应用程序控制器中的当前用户

嗨,大家好,我对rails非常陌生,如果我的问题很简单或愚蠢,请理解我。 我目前正在使用devisegem,我试图将modal放在我的application.html.erb以便模式总是出现在顶部,但我得到的错误信息是, undefined局部变量或方法`current_user’for ApplicationController:Class 我应该在哪里修复从Application.html.erb的Post.rb调用记录? 感谢您的帮助! Application.html.erb //I tried to call this 应用控制器 class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? protected @post_list = Post.where(user_id: current_user).list? def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) devise_parameter_sanitizer.permit(:account_update, keys: [:name]) end end

RSpec控制器测试错误:控制器没有实现方法

我为Devise注册编写了一些自定义代码。 即,一旦用户点击“注册”按钮,Devise的通用代码可确保正确保存用户。 但是,我想进入并确保用户获得相关的Stripe客户帐户。 下面的大部分代码来自Devise,除了我添加的几行代码: class Users::RegistrationsController < Devise::RegistrationsController def create build_resource(sign_up_params) resource.save yield resource if block_given? if resource.persisted? #### If statement below is the key custom code #### if create_stripe_customer #### Back to default Devise code #### if resource.active_for_authentication? set_flash_message :success, :signed_up if is_flashing_format? sign_up(resource_name, resource) respond_with resource, location: after_sign_up_path_for(resource) else set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if […]

如何解决此Devise身份validation挑战?

大家好,我在这里面临一些挑战,为用户设计认证: 我的应用程序中有两个名为color和sub_color的模型。 sub_color belongs_to颜色和颜色has_many sub_colors.I已经用适当的数据为数据库播种了 挑战; 我希望用户能够在设计注册为集合对象时在设计form_for中选择这些,并且sub_color的id也将用于识别特定用户(例如我可以对所有用户进行排序的情况)蓝色(蓝色)。 我该如何做到这一点? 这是我尝试过的,但它不起作用: %= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> model for users: belongs_to :sub_color has_one :color, through: :sub_color devise……. end model for sub_color has_many :users belongs_to :color end model for color has_many :sub_color end 这是我在网络浏览器上看到的错误 NoMethodError in Devise::Registrations#new [undefined method `color_id’ for #]

数组不会持久保存到数据库

我正在尝试在我的数据库中存储一个数组(:vehicles)。 该arrays由用户通过复选框选择的3种可能的车辆组成。 ‘:vehicles’属性类型是’text’,我使用此代码使其成为一个数组: serialize :vehicles, Array 如果我发送参数,它会在数组中获取这些值。 “vehicles”=>[“0”, “1”, “2”], “commit”=>”Sign up!”, “controller”=>”registrations”, “action”=>”create” 问题是当我尝试保存时,此数组不存储在数据库中。 在数据库中,代码如下所示: vehicles: [] 控制器代码: def create @student = Student.create(student_params) if @student.save! redirect_to @student else render :new end end 学生参数: def student_params params.require(:student).permit(availabilities_attributes: [ :id, :day, :available]) end 任何人都知道如何将这些值放入此数组中? 谢谢!

如何在ActiveAdmin中覆盖“after_sign_up_path_for”?

我正在构建一个Rails应用程序(使用ActiveAdmin和Devise ),我试图覆盖after_sign_up_path_for以在注册后更改重定向。 我从设计中遵循了这个教程 ,但我的RegistrationsController从未被调用过。 我想它可能与ActiveAdmin有点不同。 我还尝试了其他解决方案,我发现堆栈溢出没有任何运气。 这是我的路线 : Rails.application.routes.draw do devise_config = ActiveAdmin::Devise.config devise_config[:controllers][:omniauth_callbacks] = ‘users/omniauth_callbacks’ devise_config[:controllers][:registrations] = ‘registrations’ devise_for :users, devise_config ActiveAdmin.routes(self) # other routes end 而我的RegistrationsController :(从未调用过) class RegistrationsController < ActiveAdmin::Devise::RegistrationsController protected def sign_up(_resource_name, _resource) true end def after_sign_up_path_for(_resource) root_url end end 谢谢你的帮助 ! 我的项目 : Rails 4.2.6 ActiveAdmin 1.0.0.pre2 设计3.5.9

在设计生成的模型中删除用户

首先,我是铁杆新手。 我使用devise gem进行用户身份validation。 现在我想为管理员提供一种删除其他用户的方法。 用户的id未传递给我的destroy操作。 这是我的代码 user_controller.rb class UsersController < ApplicationController def destroy User.find(params[:id]).destroy redirect_to dashboard_path end end dashboard.html.erb |

Rails:切换用户Gem以及切换回原始用户的问题

在我的应用程序中,我使用switch_user ( https://github.com/flyerhzm/switch_user )gem来允许管理员以另一个用户身份登录。 gem有能力以管理员身份重新登录,但我很难概念化如何做到这一点。 这是我的配置: SwitchUser.setup do |config| # provider may be :devise, :authlogic, :clearance, :restful_authentication, :sorcery, or :session config.provider = :devise # available_users is a hash, # key is the model name of user (:user, :admin, or any name you use), # value is a block that return the users that can be […]