Tag: 设计

Rails:为什么RSpec会崩溃我的被覆盖的Devise控制器请求规范?

更新:哦,好悲伤,这是一个糟糕的合并后的红鲱鱼。 沿着这条线的某个地方,以下内容从spec / spechelper.rb的清理中删除 Dir[“#{Rails.root}/app/**/*.rb”].each {|f| load f} 现在这已经恢复,一切都在恢复。 我怀疑它只是加载平面目录,而不是嵌套目录,使它看起来像命名空间问题。 (我不能回答我自己的问题,因为这是一个新帐户,我没有代表) 原始问题: 我的大多数RSpec / Capybara测试工作正常,但我有一个测试只是试图访问路径爆炸,我坚持调试。 我怀疑这是一个命名空间问题,但我不知道如何解决这个问题; 任何帮助感激不尽。 整个测试是: require ‘spec_helper’ describe ‘Registrations’ do context ‘when debugging the blocking issue’ do it ‘this minimal test should pass’ do visit new_user_registration_path end end end 错误消息是: $ bin / rspec spec / requests / users / registrations_spec.rb 失败: […]

无法找到路径“/ sessions / user”的设计映射设计错误

最近几天非常令人沮丧。 我有一个安装了Devise的rails应用程序,我生成了一个新的User模型,我也生成了Devise视图。 当我在填写电子邮件和密码字段后单击“登录”时尝试以现有用户身份登录时会发生这种情况: AbstractController::ActionNotFound – Could not find devise mapping for path “/sessions/user”. This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get “/some/route” => “some_devise_controller” end 2) You are testing a Devise controller bypassing the router. If so, you can explicitly […]

如何在浏览器关闭时清除设计会话?

我在我的ruby on rails app上使用’devise’进行密码validation。 一旦我成功登录并关闭浏览器并打开一个新的浏览器窗口,我仍然登录。假设我正在使用Chrome,我关闭所有chrome实例,然后打开一个新的。 我仍然登录。当我在做IE和Firefox时也是如此。 我会假设关闭窗口并打开一个新窗口应该在服务器和浏览器之间建立一个新的会话不是吗? 如果不是我如何实现这一目标? 我曾经尝试点击浏览器窗口的onbeforeunload事件上的注销按钮,但它不起作用,因为它在任何表单提交或链接点击时注销应用程序。 window.onbeforeunload = function() { $(‘#logout_cls’).click(); }; 并尝试向会话控制器发送AJAX请求销毁用于清除会话的操作。 jQuery(window).bind( “close”, function(event) { $.ajax({ type: ‘DELETE’, dataType: ‘json’, url: $(‘#logout_cls’).attr(‘href’) }); }); 但这一切都行不通。

设计,Omniauth和Twitter

我正在开发一个使用devise和omniauth的Rails 3应用程序,并按照https://github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview中给出的示例进行操作,它适用于Facebook帐户,但是当我尝试添加Twitter auth,我收到了’401 Unauthorized’回复。 为了跟踪问题,我将api.twitter.com的URL切换为http并转储网络流量,看起来它是两次POST到/ oauth / access_token。 我第一次得到200响应,第二次得到401.在它之间使用’GET /1/account/verify_credentials.json’方法成功获取经过身份validation的用户的用户信息。 我不明白为什么代码第二次调用access_token方法。 在我的config / initializers / devise.rb文件中,我添加了: config.omniauth :twitter, “consumer_key”, “consumer_secret” 除了上面的Omniauth概述页面中列出的其余代码。 我还在我的OmniauthCallbacksController中添加了一个’twitter’方法,但由于401,它永远不会被调用。 任何帮助将非常感激。

如何设置只有用户已登录时才设计RegistrationsController来显示sign_up页面?

我试图通过谷歌和SO在这里找到解决方案但是找不到…… 这是唯一的问题。 它只有一个答案,它已被接受,但对我不起作用……这是我的代码: class RegistrationsController < Devise::RegistrationsController before_filter :authenticate_user! def new puts "Method new was called" super end end 当我没有登录localhost:3000/sign_up页面正常显示,并且打印了Method new was called 。 如果我还没有登录,我希望控制器将我重定向到sign_in页面。当然我可以用new方法检查它并重定向,但这不是一个好的解决方案……我确信有更优雅的方式。 我甚至尝试使用prepend_before_filter :authenticate_user! 但它也不起作用。 编辑 我在routs.rb中为这个控制器定义了路由 devise_for :users, :controllers => { :sessions => “sessions”, :registrations => “registrations” }

当有STI时,Rails设计为注册表单添加字段

这是我的模特: class User ‘Worker’, :foreign_key => :worker_id devise :database_authenticatable accepts_nested_attributes_for :worker attr_accessible :worker_id, :email, :password, :password_confirmation, :remember_me, :workers_attributes, :worker_attributes, :name, :worker end class Worker < User devise :database_authenticatable, :registerable belongs_to :user attr_accessible :name, :worker, :workers end 我正在尝试将字段名称添加到http:// localhost:3000 / workers / sign_up的注册表单中 注册表格 Create Worker resource_name, :url => registration_path(resource_name) do |f| %> Name: “devise/shared/links” %> […]

使用Ruby on Rails设计 – 强制用户在首次登录时更改密码

我有一个运行Devise的RoR应用程序(Rails 4.2,Ruby 2.2.0)。 我已将其设置为管理员用户(标识为我添加到用户模型的“is_admin”布尔值)能够创建新用户帐户,为他们提供生成的密码和确认电子邮件。 这一切都正常。 我还添加了datetime列pass_changed,应该在用户更改密码时更新,然后检查created_at以确保自创建帐户后密码已更改。 如果两个日期相等,则将用户重定向到密码更改表单。 我写了一个程序来检查用户是否更改了密码并将其放在我的application_controller.rb中: def check_changed_pass @user = current_user if @user.pass_changed == @user.created_at #make sure user has changed their password before accessing internal pages redirect_to edit_user_registration_path, alert: “You must change your password before logging in for the first time” end end 然后在我的internal_controller.rb中(用于需要用户登录的所有内部: before_action :check_changed_pass 到目前为止一切顺利,但问题在于尝试在正确的时间更新pass_changed。 我已经尝试了各种配置,但我找不到放置此代码的位置,以便在更新密码时触发,但不是每次更新用户模型时都会触发,包括每次登录和注销,当我只想要它时如果密码更新,则触发。 如果我在我的控制器中放置“before_save:update_pass_change,only:[:edit,:update]”,它不会在密码更新时触发,如果我将它放在User模型中,我必须将该过程放在模型中同样,然后它不会拾取current_user,因为它在模型中不可用。 理想的是,如果Devise有一个类似于after_database_authentication挂钩的after_password_edit挂钩。 我不得不重写Devise的registrations_controller.rb来删除该行 prepend_before_filter :require_no_authentication, […]

设计不适用于RoR3应用程序上的多个子域

我已经看到很多关于这个主题的问题,但是很多问题都有相互矛盾的信息,并且由于某些原因它对我没有用。 我有: 顶级域名:即lvh.me(开发)。 每个用户都有子域名:ie userdomain.lvh.me登录表单位于顶级域名:lvh.me 我想要: 如果用户登录,则需要在所有子域之间共享会话。 我的意思是,会话需要在lvh.me:3000/something和userdomain.lvh.me:3000中激活 如果用户从lvh.me:3000/something注销它应该工作,如果用户从userdomain.lvh.me:3000注销,它也应该工作。 我试过了 在初始化程序中设置以下内容: MyApplication :: Application.config.session_store:cookie_store,:key =>’_ mykey’,:domain =>:all 发生了什么? 我可以登录lvh.me:3000,我正确地重定向到lvh.me:3000/internalpage,如果我去subdomain.lvh.me:3000它很棒。 我也可以从lvh.me:3000/internalpage注销但是如果我尝试从subdomain.lvh.me:3000注销它不起作用。 Devise SessionsController中的destroy动作被执行,但是会话并没有消失。 根据http://excid3.com/blog/sharing-a-devise-user-session-across-subdomains-with-rails-3/ , 这里的诀窍是:域选项。 它的作用是设置TLD(顶级域)的级别,并告诉Rails域的长度。 你要注意的部分是,如果你设置:domain =>:在某些地方建议使用all,除非你使用localhost,否则它将无法工作。 :所有默认值都是TLD长度为1,这意味着如果您使用Pow(myapp.dev)进行测试,它将无法工作,因为这是一个长度为2的TLD。 所以,看完之后我也试过了 MyApplication :: Application.config.session_store:cookie_store,:key =>’_ mykey’,: domain =>’lvh.me’ 发生了什么? 我可以登录lvh.me:3000,我正确地重定向到lvh.me:3000/internalpage,如果我去subdomain.lvh.me:3000它不起作用,我没有会话。 如果我回到lvh.me:3000/internalpage我的会话已经消失了。 那里发生了什么? 还有什么? 然后,在读取rails 3.2子域并设计后,我将初始化器行更改为 MyApplication::Application.config.session_store :cookie_store, :key => ‘_mykey’, :domain => ‘.lvh.me’ 注意“。” 在域名之前。 根据SO中的post: […]

Ruby on rails使用rest API调用和Devise进行用户注册

任何人都可以指导我如何在ruby on rails上从移动设备(rest API)注册用户。 我正在使用Devise with Rails 3.0。 它给了我以下错误 Devise中的NameError :: CustomRegistrationsController #create

Rails – 如何创建链接到另一个模型的TWO的模型

我正在尝试创建以下内容: User model (this is fine) id Link model (associated with two Users) id user_id1 user_id2 这是一个我想在Link模型上使用has_and_belongs_to_many关联类型的实例吗? 我该怎么做? 最终,我希望能够拥有一个用户对象并调用@ user.links来获取涉及该用户的所有链接… 我只是不确定在Rails中最好的方法是什么。