Tag: 设计

Devise中的LoadError :: RegistrationsController #create(无法加载此类文件–bcrypt_ext)。 为什么我会收到此错误?

我正在使用ruby 2.2.4。 我在安装Devise gem之后尝试注册时遇到此错误。 我曾经使用过ruby 2.1.5时从未遇到过这个错误。 ruby版本是错误的原因吗? 更新:这是我的gemfile的样子,我正在使用Windows 7 Professional 64位 source ‘https://rubygems.org’ gem ‘rails’, ‘4.2.5.1’ gem ‘sqlite3’ gem ‘sass-rails’, ‘~> 5.0’ gem ‘uglifier’, ‘>= 1.3.0’ gem ‘coffee-rails’, ‘~> 4.1.0’ gem ‘jquery-rails’ gem ‘turbolinks’ gem ‘jbuilder’, ‘~> 2.0’ gem ‘simple_form’, ‘~> 3.2’, ‘>= 3.2.1’ gem ‘country_select’, ‘~> 2.5’, ‘>= 2.5.1’ gem ‘devise’, ‘~> 3.5’, ‘>= […]

Rails注册用户使用电话号码和确认

我正在为它构建一个iPhone应用程序和rails后端。 我希望用户通过他们的电话号码和使用SMS发送的确认码进行注册。 它应该像WhatsApps身份validation一样工作。 有没有人知道gem,理想的是设计,或者我必须自己构建它?

过滤链停止为:doorkeeper_authorize! 渲染或重定向

我正在构建一个Rails API,目前正在使用门卫并设计使用ResourceOwnerFromCredentials流来validation用户。 一切正常,但我无法在Rspec中使用身份validation。 以下是如何在rspec中集成应用程序: let(:app_country) { FactoryGirl.create(:app_country)} let(:valid_attributes) { FactoryGirl.attributes_for(:app_city, {:app_country_id => app_country.id}) } let(:valid_session) { {:format => :json} } let(:application) { Doorkeeper::Application.create!(:name => “App HQ dashboard”, :redirect_uri => “https://localhost:3000/callback”) } let(:hq_user) { app_country.hq_users.create!(FactoryGirl.attributes_for :hq_user) } let(:token) { Doorkeeper::AccessToken.create! :application_id => application.id, :resource_owner_id => hq_user.id } 但每次我尝试测试受保护的操作时,测试都会失败,我从控制台获得以下输出: Filter chain halted as :doorkeeper_authorize! rendered or redirected […]

让用户使用Facebook登录或创建帐户

此时用户可以使用omniauth-facebook gem的facebook帐户登录我的网站。 我还想为用户实现一种方法,即使用类似设计的gem创建一个帐户,这样他们在发布时可以保持更加匿名。 这是我在sessions_controller中的内容 class SessionsController < ApplicationController def create user = User.from_omniauth(env["omniauth.auth"]) session[:user_id] = user.id redirect_to root_url end def destroy session[:user_id] = nil redirect_to root_url end end 然后我的用户模型 class User < ActiveRecord::Base include SessionsHelper def self.from_omniauth(auth) where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| user.provider = auth.provider user.uid = auth.uid user.name = auth.info.name user.oauth_token = auth.credentials.token user.oauth_expires_at = […]

在错误登录进入登录页面后,按下正确登录按钮

我正在使用设计,我面临一个有趣的用例。 在页面: http://localhost:3000/users/sign_in ,如果我输入正确的登录ID和密码,我登录该网站。 现在,如果我按回按钮,它表示你已经登录了。 但在页面: http://localhost:3000/users/sign_in ,我输入错误的登录ID和密码,它给出错误,并再次保留在此页面。 我输入正确的登录ID和密码,我登录该网站。 现在,如果我按下后退按钮,它将进入登录页面。 我该怎样克服这一点

如何在不通过表单传递数据的情况下更新嵌套资源

楷模 class User :destroy, :inverse_of => :user has_many :companies, :through => :roles accepts_nested_attributes_for :roles, :limit => 1, :allow_destroy => true end class Role :roles belongs_to :company, :inverse_of => :roles accepts_nested_attributes_for :company end class Company :destroy, :inverse_of => :user has_many :users, :through => :roles validates :name, presence: true end 自定义设计注册控制器 class RegistrationsController < Devise::RegistrationsController # GET […]

当我使用Sendgrid Rails Heroku发送电子邮件时,如何获取或访问不同的模型属性

我正在使用装饰和搭建教科书。 我喜欢实施我的策略。 当买家点击@ textbook.title时 – >买家可以向@教科书的卖家发送电子邮件。 我的每个模型都有’user_email’列。因此,每当卖家创建一个@textbook时,自动将current_user.email保存到@ textbook.user_email中。 我只是不知道如何抓住卖家的user_email并发送电子邮件。 我有以下 教科书模型: class Textbook true validates :subject, :presence => true validates :price, :presence => true validates :offer, :presence => false validates :created_at, :presence => false validates :user_email, :presence => true validates :description, :presence => true end 我不确定这个模型语法是否适合主题和current_user.email联系模型: class Contact true attribute :current_user.email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i attribute […]

Rails Concerns,Scopes,Devise,User.current和current_user

我正在考虑根据状态显示记录。 如果您已登录,则可以看到未批准的记录,公众只能查看已批准的记录。 module Approved extend ActiveSupport::Concern included do if User.current && !User.current.nil? scope :approved, -> { where(“#{self.table_name}.status_id IN (1,2,3)”) } else scope :approved, -> { where(“#{self.table_name}.status_id IN (1)”) } end end end 我正在使用Thread来设置当前用户。 def self.current=(user) Thread.current[:current_user] = user end def self.current Thread.current[:current_user] end 在application_controller中,我有一个before_action调用set_current_user。 def set_current_user User.current = current_user end 当我注销未经批准的记录时,仍会从查询中提取。 它似乎跳过了这个问题。

将设计和omniauth处理为失败的Google oauth2

我正在尝试配置一个新的rails4.2应用来对Google Oauth2进行身份validation。 我似乎成功地完成了整个过程,但它被视为失败。 最初的授权似乎进展顺利,直到谷歌发送回调。 然后它似乎被错误地识别为失败。 给出的错误消息是: Could not authenticate you from Google because “Invalid credentials”. 我已经google了解决方案,但无济于事。 是否可以打开其他日志记录以了解它为什么选择通过故障方法进行处理? 这是请求的日志: Started GET “/users/auth/google” for 127.0.0.1 at 2016-04-17 09:37:33 +0800 Started GET “/users/auth/google/callback?state=<>&code=<>” for 127.0.0.1 at 2016-04-17 09:37:45 +0800 Processing by Users::OmniauthCallbacksController#failure as HTML Parameters: {“state”=>”<>”, “code”=>”<>”} Redirected to http://test_app.dev/sign_in Completed 302 Found in 1ms (ActiveRecord: 0.0ms) 在测试时,我点击了谷歌提示我的时候允许,并且url看起来很好,那么为什么这个被处理好像是失败的呢? […]

注册后如何使用Device自动登录?

在我的rails应用程序中,我使用devise gem来管理用户。 我使用mobile_fu gem来分隔来自不同用户的用户。 我想在这里实现的是: 如果用户从移动设备打开我的站点,我将提取其已经完成的MSISDN号码读取标题 如果该MSISDN号码属于特定系列,那么我想自动将该用户登录到我的网站,这样他就不必填写sign_in表单。 我怎么能做到这一点?