Tag: 设计

使用自定义注册控制器进行设置

我正在使用设备工作在rails网站上,我们还不想要用户注册。 用户身份validation是我们可以登录访问网站的受限制部分,并根据需要添加/编辑内容。 所以现在,我创建了以下控制器: class Users::RegistrationController < Devise::SessionsController def new end end 并以这种方式设置我的路线: devise_for :users, :controllers => { :registration => “users/registration” } 但是,当我运行rake路由时,我仍然在注册控制器上看到create action的返回值。 关于如何摆脱它的任何想法?

是否可以在确认后添加闪存消息的链接?

我正在使用Devise。 当用户成功确认时,将显示flash消息。 我想添加一个链接。 所以我想要这条消息 Your account was successfully confirmed. You are now signed in. Go to your profile page, and edit it! 然后, profile的一部分应该是example.com/users/username/edit的链接 我怎样才能成功呢? devise.en.yml confirmations: confirmed: ‘Your account was successfully confirmed. You are now signed in.’

通过Resque发送Devise电子邮件

我正在尝试通过Resque发送Devise电子邮件。 通过Resque发送的常规电子邮件就好了。 并且Devise电子邮件发送得很好,但不会通过Resque发送电子邮件。 我得到“找不到有效的映射”,这意味着我的帮助程序覆盖不会被拾取。 我正在关注这个http://shaker.4-dogs.biz/2011/08/06/using-resque-to-send-mail-for-devise/ 奇怪的是,调试它我正在使用Devise的本地副本,并在Devise中的’initialize_from_record’中添加断点,当我仅使用Devise时会受到攻击。 但是当我通过resque发送Devise电子邮件时,断点不会受到影响: class ResqueMailer < Devise::Mailer include Resque::Mailer end config.mailer = "ResqueMailer" 而resque则显示一个打包的gem路径,而不是我的本地源,例如: /Users/mm/.rvm/gems/ruby-1.9.2-p290@evergreen/gems/devise-1.4.9/lib/devise/mailers/helpers.rb:20:in `devise_mail’ 知道为什么它没有使用我的本地gem源和/或如何让Resque发送我的Devise电子邮件?

有条件地将skip_before_filter应用于:如果=>条件在rails 4中

我有一个Events控制器,我想要跳过身份validation,因为事件是公开的。 在我的ApplicationController我调用了devise的authenticate_user! class ApplicationController < ActionController::Base before_action :authenticate_user! end 现在,在我的事件表中,我有一个名为public的布尔字段。 我用它来检查事件是否公开。 在EventsController像这样 class EventsController < ApplicationController skip_before_action :authenticate_user!, only: :show, if: Proc.new { :is_public? } end 但由于某种原因,这不起作用。 所以我必须这样做: class EventsController < ApplicationController skip_before_action :authenticate_user!, only: :show before_action :authenticate_user!, unless: :is_public? def is_public? @event.present? && @event.is_public end end 如果@event.public = true这可以按预期工作并跳过身份validation,因为上面的内容在跳过后重复带有反向条件的before_filter 。 我想知道: 我做的是对的吗? 这是否会对性能产生影响。 如果有,那么还有更好的方法吗?

通过json设计失败认证发回html而不是json

我已设法设置json身份validation。 我实现了以下代码: class Users:: SessionsController resource_name, :recall => “#{controller_path}#failure”) render :json => {:success => true} } end end def destroy respond_to do |format| format.html {super} format.json { Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) render :json => {} } end end def failure render :json => {:success => false, :errors => [“Login Failed”]} end end 这很好,但是当身份validation失败时,失败并不会返回json失败。 我有一个定制的设计失败。 […]

如何在没有数据库的情况下使用Rails / Devise?

我正在创建一个不使用数据库的Rails应用程序。 相反,使用包装遗留系统的Ruby API来管理模型。 我有一个Ruby调用,允许我validation用户名/密码组合。 在这种情况下是否可以使用Devise(或其他一些现成的身份validation解决方案)? 我希望我可以在Devise中覆盖一些方法,并且仍然可以获得许多好处。 彼得。

Google OAuth 2 redirect_uri_mismatch – OmniAuth Rails应用

我在使用Rails应用validationGoogle帐户时遇到问题。 我正在使用带有Devise的omn​​iauth-google-oauth2 gem 。 我尝试访问Google帐户时始终收到此错误消息: Error: redirect_uri_mismatch The redirect URI in the request: http://localhost:3000/users/auth/google_oauth2/callback did not match a registered redirect URI 我确信我的Google控制台应用中注册的重定向URI是正确的,与请求的相同,就像这样: 那么这里的主要问题是什么?

如何为Rails设置远程json API以进行身份​​validation和会话

我是rails的新手,对Devise Gem有一个非常基本的了解。 除了CRUD和观点我不清楚它提供什么可以帮助我使用AngularJs应用程序与Rails Json Api交谈。 目前,我正在努力推动事物。 为了安全,我在客户端(js)和服务器之间交换HTTP标头令牌。 我也使用Railscast#250进行用户身份validation – 但我没有看到如何将SessionController应用于远程客户端。 是否有任何策略可用于通过远程json API进行身份validation和管理会话? 谢谢!

NameError(未定义的局部变量或方法`devise_parameter_sanitizer’

我正在使用设计进行用户身份validation。 但是,当用户尝试创建帐户时,我收到此错误: NameError (undefined local variable or method `devise_parameter_sanitizer’ 这就是我的设计注册控制器的样子: def sign_up_params devise_parameter_sanitizer.for(:sign_up) end 有任何想法吗? 提前致谢

允许用户仅从索引编辑/销毁自己的配置文件

如何在rails的用户索引中授予按用户编辑/销毁链接的权限? 我正在使用Rails3,Devise和CanCan来定义基于角色的能力。 我希望当前用户能够在用户索引页面中查看和访问用于编辑/删除其个人资料的链接。 他们不应该能够为所有其他用户查看或访问这些链接。 我在索引视图中设置了以下内容: | 并在abilities.rb def initialize(user) can :update, User, :id => user.id if user.role? :super_admin can :manage, :all end end 我的superadmin可以查看和编辑索引中所有用户的链接。 我的用户可以看到没有人的链接,甚至连自己都没有。 我读到的越多,我就越困惑,设计,康康和用户模型都起到了作用。 我很欣赏我已经走上了正确的道路,并且非常感谢能够帮助我理解这一点的有用信息。 非常感谢