Tag: 设计

Rails / Devise – 如何显示注册信息(不仅仅是编辑它)

我今天安装了Devise,到目前为止一切正常。 似乎没有提供的唯一设施是“注册#show”动作,它显示用户信息(而不是注册编辑页面)。 我试图覆盖注册控制器,但得到错误:’Unknown action-AbstractController :: ActionNotFound’用于此控制器上的所有操作。 有人知道如何显示个人资料信息吗? 谢谢! class RegistrationsController < Devise::RegistrationsController def new super end def create super end def show end def update super end end

更改密码后用户会话无效,但只有多个线程

我的Rails 4 + Devise 3.2应用程序中的一个function遇到了一个奇怪的问题,它允许用户通过AJAX POST将其密码更改为以下操作,该操作源自Devise wiki 允许用户编辑其密码 。 似乎在用户更改密码之后以及之后的一个或多个请求之后,它们将被强制注销,并在重新登录后继续被强制注销。 # POST /update_my_password def update_my_password @user = User.find(current_user.id) authorize! :update, @user ## CanCan check here as well if @user.valid_password?(params[:old_password]) @user.password = params[:new_password] @user.password_confirmation = params[:new_password_conf] if @user.save sign_in @user, :bypass => true head :no_content return end else render :json => { “error_code” => “Incorrect password” […]

设计:能够将参数传递给注册#sign_up动作

偶尔我们会向我们的潜在客户发送定制的注册链接。 该链接包含的参数可用于预填充注册表单。 http://www.example.com/users/sign_up?user[company_name]=Foo&user[region]=NA 我们的注册表包含接受公司名称和地区的字段。 哪个可以根据注册链接预先填写。 这应该在实践中起作用,但它不是由于registrations#new动作的实现方式。 新操作使用空哈希调用build_resource方法。 def new resource = build_resource({}) respond_with resource end 当输入为非零时,build_resource方法忽略resource_params 。 def build_resource(hash=nil) hash ||= resource_params || {} self.resource = resource_class.new_with_session(hash, session) end 我不得不在我的注册控制器中超越new动作来克服这个问题。 我不喜欢我的解决方案,因为它很脆弱。 def new resource = build_resource respond_with resource end 是否有理由使用空哈希调用new操作? 是否可以使用空哈希调用(如在create操作中)?

Rails会在24小时内过期密码

在我的rails 3.1应用程序中,我想为用户创建并过期随机密码。我正在使用devise gem.Any插件可用于expiring password吗? 或者请给我一些合理的建议来实现这个function。 请认为我是新手。

单一登录与设计和OmniAuth

有很多关于使用OmniAuth和Devise能够使用facebook和twitter登录webapp的信息。 但是,我正在尝试编写自己的OAuth提供程序而不使用fb / twitter等(并且未能找到示例)。 我基本上想要有两个应用程序 – 一个UserManager,它有一个用户表,和WebApp1(以及将来可能更多)。 我希望用户能够转到WebApp1并重定向到UserMAnager以便能够登录,然后重定向回WebApp1。 我不希望WebApp1有一个用户表。 我可以指点一下吗? 在这个阶段,我相信我需要在两个应用程序中使用Devise,在WebApp1中需要OmniAuth,尽管我不是100%肯定。

使用MailCatcher和Devisegem的Rails 4

我有一个与gemDevise的应用程序。 我需要通过电子邮件确认注册。 在config / environment.rb中我添加了这个 ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = { :address => “smtp.gmail.com”, :port => 587, :domain => “gmail.com”, :authentication => ‘plain’, :user_name => “myappname@gmail.com”, :password => “mypassword” } 在config / environment / development.rb中添加: config.action_mailer.default_url_options = { :host => ‘localhost:3000’ } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => “127.0.0.1”, :port => 1025 } […]

rails在集成测试中设计经过身份validation的路由

我想测试一个应用程序中的每个路由,并了解到我应该在集成测试中做到这一点: 在轨道上的ruby中测试路由的位置 但是我收到以下错误: NoMethodError: undefined method `authenticate?’ for nil:NilClass /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise-2.1.2/lib/devise/rails/routes.rb:286:in `block in authenticated’ 网上有很多人提到你不能在集成测试中使用Devise :: TestHelpers – Devise Google Group , Devise Github page 如何测试以下路线? # config/routes.rb devise_for :users authenticated :user do root to: ‘static#home’ end root to: ‘static#landing’ 我正在使用$ rake test:integration测试unit testing

如何在一个关系中使用accepts_nested_attributes_for设计?

我试图让我的用户表单也允许用户通过form_for同时填写他们的公司资料。 由于某种原因,它没有显示公司字段。 这是我的控制器和布局代码。 class User < ActiveRecord::Base attr_accessible :company_attributes has_one :company accepts_nested_attributes_for :company end class Company true end

使用Devise更新密码后,如何让用户保持登录状态?

每当用户更新其密码时,它都会向用户签名并要求他们再次登录。 这是我的行动 users_controller.rb def update @user = User.find(params[:id]) if @user.update user_params sign_in @user, bypass: true # for some reason Devise signs the user out redirect_to @user http://www.rubydoc.info/github/plataformatec/devise/Devise/Controllers/SignInOut#sign_in-instance_method 我也试过了sign_in @user , sign_in @user 。 我尝试了没有sign_in但这也没有用。 我看到了这个答案,但它没有帮助: Devise在密码更改后注销用户 。 没有密码更新用户正常。 (有些代码没有显示。) 设计3.4.1。

设计…用户模型未validation的其他列

我在Rails 3应用程序中使用Devise进行身份validation。 我通过db:migrate将first_name和last_name列添加到数据库中。 注册表格修改如下: resource_name, :url => registration_path(resource_name)) do |f| %> 用户模型中的validation: validates :first_name, :last_name, :email, :password, :password_confirmation, :presence => true 由于某种原因,我得到“名字不能为空”和“姓氏不能为空”validation错误。 有趣的是,除了库存Devise字段之外,还添加了两个字段。 Devise是否阻止向User模型添加其他字段? 还有什么其他原因? 谢谢。