Tag: 设计

使用Devise和Omniauth的路由问题

我试图让OAuth和Devise一起工作,但我得到Controller::RoutingError (No route matches “/users/auth/facebook/callback”):当试图通过Facebook进行身份validation时。 奇怪的是,Google Apps不会出现此问题。 (相同的回调路线)。 有任何想法吗? callback_controller: class Users::OmniauthCallbacksController “Facebook” sign_in_and_redirect @user, :event => :authentication else session[“devise.facebook_data”] = env[“omniauth.auth”] redirect_to new_user_registration_url end end def google_apps @user = User.find_for_google_apps_oauth(env[“omniauth.auth”], current_user) if @user.persisted? flash[:notice] = I18n.t “devise.omniauth_callbacks.success”, :kind => “Google Apps” sign_in_and_redirect @user, :event => :authentication else session[“devise.google_apps_data”] = env[“omniauth.auth”] redirect_to new_user_registration_url end end […]

如何将Devise的Rails应用程序转换为OAuth提供程序?

我有一个使用Devise进行身份validation的管理员帐户的Rails应用程序。 我正在创建第二个应用程序,并希望使用第一个应用程序进行身份validation,而不是在第二个应用程序中复制管理员帐户。 所以我的想法是将第一个应用程序转换为OAuth提供程序,以便第二个应用程序可以像OmniAuth一样充当OAuth客户端。 你以前做过这个吗? 是否有一个插件可以增加Devise的能力,使其能够充当OAuth提供者? 为了将应用转变为OAuth提供商,我需要更改/添加什么?

使用Rspec 2和Devise在Rails 3中测试助手

我的帮助程序代码看起来像这样(并且工作正常btw): module ProvidersHelper def call_to_review(provider) if user_signed_in? && review = Review.find_by_provider_id_and_user_id(provider.id, current_user.id) link_to “Edit Your Review”, edit_provider_review_path(provider, review), :class => “call_to_review” else link_to “Review This Provider”, new_provider_review_path(provider), :class => “call_to_review” end end end 不幸的是,当我运行我的测试时,这会产生以下错误: undefined method `user_signed_in?’ for # # ./app/helpers/providers_helper.rb:3:in `call_to_review’ 很明显,当rspec运行测试时, Devise::Controllers::Helpers不会包含在我的助手中。 任何可能有助于此工作的建议? 编辑:为了提供更多信息,我的spec_helper确实有这个: config.include Devise::TestHelpers, :type => :controller config.include Devise::TestHelpers, :type => […]

Ruby on Rails登录后设计代码

我有一个使用Devise登录的RoR应用程序。 创建新用户记录时会执行一些代码,方法是将user.rb文件作为after_create调用/ macro / whatever放入。 我需要在每次登录后运行此代码,而不是在新用户创建时运行。 通过一些谷歌搜索,似乎有一个选项是在devise.rb代码中放置Warden回调。 我的问题是: 这是对的吗,和/或有更好的方法吗? 如果这是正确的方法…… Warden :: Manager …方法defs应该在Devise.setup中的devise.rb中,还是在它之后? after_authentication我应该使用回调吗? 我只是检查是否存在基于用户名的目录,如果不存在,则创建它。

Rails 4如何在出错时覆盖设计响应路径

我一直在努力争取这个。 我有一个Rails4 / Devise 3.1应用程序,系统中有两个用户: gradle生 雇主 和一个设计用户可以通过多态:profile关联成为研究生或雇主。 我有gradle生通过/graduate/sign_up路径和雇主通过/employer/sign_up路径注册两个路由到相同的/views/devise/registrations/new.html.erb视图(因为他们的注册表格几乎相同 -电子邮件和密码)。 一切正常,除非有validation错误, RegistrationsController#create.respond_with resource总是将两个用户类型重定向到/users路径,我需要将它们重定向回原来的位置,例如/graduate/sign_up或/employer/sign_up分别是/employer/sign_up 。 我尝试用redirect_to替换respond_with ,但最终我丢失了带有相关错误消息的资源对象。 谁知道如何做到这一点? 这些是我的模特: class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable belongs_to :profile, polymorphic: true end class Graduate < ActiveRecord::Base has_one :user, as: :profile end class Employer < ActiveRecord::Base has_one :user, as: :profile end 注册管理员: class RegistrationsController […]

为什么这个rspec请求规范没有更新模型?

我有与User模型交互的请求规范。 我想确保具有Admin角色的用户可以创建/编辑/销毁用户。 我现在遇到问题,编辑操作不会更新用户。 当我手动浏览网站上的操作时,一切正常,但测试无法更新用户。 这是我的规格: it ‘edits a user’ do @user = FactoryGirl.create(:user) visit new_user_session_path unless current_path == new_user_session_path fill_in “Email”, :with => @user.email fill_in “Password”, :with => @user.password click_button “Sign In” user_to_edit = FactoryGirl.create(:user, first_name: “John”, last_name: “Smith”) visit edit_user_path(user_to_edit) unless current_path == edit_user_path(user_to_edit) fill_in ‘user_last_name’, with: “Changed” expect{ click_button “Do it” }.to change […]

在任何页面上设计注册表格

我正在尝试允许用户在我的主页/目标网页上注册该网站。 我已将设计注册表复制到我的目标网页视图中 – resource_name, :url => registration_path(resource_name)) do |f| %> 我还在application_controller.rb 添加了辅助方法 ,以便我正确定义资源 – class ApplicationController < ActionController::Base protect_from_forgery def resource_name :user end def resource @resource ||= User.new end def devise_mapping @devise_mapping ||= Devise.mappings[:user] end end 但是我仍然得到错误undefined local variable or method resource’ ##:0x007fa816b4b750>` 我在这里错过了什么,以便在我的主页登陆页面上正确呈现注册表单?

如何从Rails控制台注销设计用户?

我的设计用户是“database_authenticatable”和“token_authenticatable”。 我尝试从控制台删除该用户的数据库中的“authentication_token”字段,但他们似乎仍然可以使用他们现有的身份validation令牌。 删除用户完全有效,但我不想走那么远。 编辑:为清楚起见。 我想使用rails 控制台注销用户。 即运行rails console然后运行一些命令。

RoR设计:sign_in始终返回无效的电子邮件/密码

每次登录时,都会收到错误信息,表明电子邮件/密码无效。 路线: devise_for :users devise_scope :users do get ‘/users/sign_out’ => ‘devise/sessions#destroy’, :as => :destroy_user_session post ‘/users/sign_in’ => ‘devise/sessions#create’, :as => :user_session end resources :users 用户模型: devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable attr_accessor :password attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :gender, :remember_me 视图: Hi . | Not you? :delete %> or :create %> 我尝试将路线更改为: get ‘/users/sign_in’ […]

如何在rails app中为我的用户添加角色?

我有一个简单的应用程序与设计的身份validation系统。 我尝试将角色添加到用户模型中。 但没有任何反应。 我所做的是创建了角色模型并将其链接到用户模型: $ rails g model Role name:string $ rails g migration addRoleIdToUser role:references $ rake db:migrate (按照设计维基的指示) 然后在我的模型中: class User < ActiveRecord::Base belongs_to :role end class Role < ActiveRecord::Base has_many :users end 使用我的角色设置seeds.rb: [‘seller’, ‘buyer’, ‘admin’].each do |role| Role.find_or_create_by({name: role}) end 然后 $ rake db:seed 就这样。 我还想知道如何让用户在注册时选择任何这些角色