Tag: 设计

多对多关系只能以Rails / Activerecord / devise的方式工作

我有一个多对多的关系用户到列表用户模型是用设计创建的。 出于某种原因,我无法访问任何用户的.lists。 为nil返回undefined方法`to_sym’:NilClass。 在做了一些挖掘之后我很确定我已经在_reflect_on_associationactiverecord(4.1.6)lib / active_record / reflection.rb中找到了问题 def _reflect_on_association(association) #:nodoc: _reflections[association.to_sym] end 协会正在以零传递。 有没有人遇到过这个问题? 在rails控制台中测试关系 [15] pry(main)> testuser = User.new => # [16] pry(main)> testlist = List.new => # [17] pry(main)> testlist.users => [] [18] pry(main)> testuser.lists NoMethodError: undefined method `to_sym’ for nil:NilClass from /Users/user/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/reflection.rb:100:in `_reflect_on_association’ [19] pry(main)> testlist.users < [#] [22] pry(main)> testuser.lists […]

rails 3:使用devise进行身份validation,如何允许使用guid而不是登录来访问报告页面

我的rails 3应用程序每个帐户只需要一个用户登录(例如,没有角色)。 我正在使用Devise,我很高兴。 但我的用户需要能够与其他不需要或不想登录帐户的经理共享一些屏幕(主要是状态报告)… 我正在考虑为每个这样的“外部”报告创建和存储一个guid(每个帐户+报告都是唯一的),所以链接如 http://myapp.mydomain.com/pagename?token=GUID_GOES_HERE 将访问该页面(但只有该页面) 问题: a)有没有办法允许登录帐户用户访问页面,但也允许guid绕过设计认证 b)帐户用户(例如,区域经理)是否有更好的方式与未登录的用户(例如,商店经理)共享某些报告屏幕?

在ApplicationController中覆盖current_user会引发未定义的方法错误

基于stackoverflow问题来覆盖devise的current_user,我写了这样的东西: class ApplicationController < ActionController::Base alias_method :devise_current_user, :current_user def current_user if !devise_current_user.nil? return # my logic end return nil end end 两个问题:1。它抛出了一个未定义的方法错误,我定义了alias_method …. 2.在devise_for方法中,我的覆盖current_user将被传递还是设计的current_user?

Rails,Devise:相同的资源,基于用户类型的不同控制器

我有一个资源,比如Product ,可以通过两个不同的用户类访问:比如Customer和Admin 。 这两者之间没有inheritance。 我正在使用Devise进行身份validation: # config/routes.rb devises_for :customers deviser_for :admins 我有这两个控制器: # app/controllers/customers/products_controller.rb class Customers::ProductsController < ApplicationController 和 # app/controllers/admins/products_controller.rb class Admins::ProductsController < ApplicationController 现在,根据谁登录( Customer或Admin ),我希望products_path指向相应的控制器。 我想避免使用customers_products_path和admins_products_path ,这很麻烦。 所以我已经设置了我的路线 # config/routes.rb devise_scope :admin do resources :products, module: ‘admins’ end devise_scope :customer do resources :products, module: ‘customers’ end 这不起作用。 当我以Customer身份登录时, products_path仍然指向Admins::ProductsController#index因为它是第一个定义的。 任何线索? 没有黑客行为,我想做的事情可能根本不可能。 更新根据代码 […]

设计:无法关闭require_no_authentication?

当我尝试限制注册访问时,似乎不可能。 我试过了 class RegistrationsController < Devise::RegistrationsController skip_before_filter :require_no_authentication end 在app / registrations_controller.rb中并​​将路由更改为 devise_for :accounts, :controllers => { :registrations => “registrations” } 这不起作用。 任何建议为什么以及我能做什么/我应该在哪里看,将不胜感激。 编辑: 不起作用意味着:当我在注销时尝试访问/ accounts / sign_up时,它确实有效,但我应该重定向到sign_in。 解决方法: class RegistrationsController < Devise::RegistrationsController skip_before_filter :require_no_authentication private def authenticate_account!(opts={}) opts[:scope] = :account warden.authenticate!(opts) # if !devise_controller? || opts.delete(:force) end end 这将删除跳过对每个Devise控制器的身份validation的硬编码检查。 代码来自lib/devise/controllers/helpers.rb 。

Rails App Refinery + Devise:无法访问Devise视图

新手Rails开发者在这里。 我正在尝试创建一个使用Devise进行身份validation和使用Refinery进行内容管理的应用。 我已经按照这些教程: http://sdownie.com/blogs/integrating-refinery-rails-3-2-into-your-existing-rails-app http://refinerycms.com/guides/with-an-existing-rails-31-devise -app 我无法访问该网站上的任何Devise视图。 例如,当我转到/ users / sign_in时,我得到404.在我的服务器日志中,我看到以下内容让我认为Refinery正在处理请求而不是Devise路由: Processing by Refinery::PagesController#show as HTML Parameters: {“path”=>”users/sign_up”} … Filter chain halted as :find_page rendered or redirected Completed 404 Not Found in 39ms (Views: 32.8ms | ActiveRecord: 1.6ms) 知道如何纠正这个并访问Devise sign_in / sign_up视图吗? 这是我的第一个stackoverflow问题,所以如果我需要添加更多具体信息,请告诉我。 非常感激

Cancan +设计rescue_from没有捕获exception

我正在实现Devise和Cancan用于用户身份validation和权限。 到目前为止,一切都很好,但我不能在不允许用户访问特定function时将用户重定向到登录页面。 我的测试是: feature ‘A signed in user’ do before(:each) do user = FactoryGirl.create(:user) visit “/login” fill_in “user_email”, :with => user.email fill_in “user_password”, :with => “ilovebananas” click_button “Sign in” end scenario ‘should not have access to admin dashboard’ do visit ‘/admin’ page.should have_content ‘Log in’ end end 我得到以下失败: Failures: 1) A signed in user should […]

设计登录时重置会话

我在application_controller.rb文件中定义了以下内容: def redirect_back_or(default) redirect_to(session[:return_to] || default) session.delete(:return_to) end def store_location session[:return_to] = request.url end def after_sign_in_path_for(resource) r = session[:return_to] || user_root_url session.delete(:return_to) r end 我正在尝试将用户发送回sign_in之前来自他们的地方,或者,如果没有保存位置,则将其发送到他们的根页面。 我在我的一个控制器中调用它: if current_user.nil? store_location redirect_to home_login_url, alert: “You must be logged in to purchase subscriptions” return end 我通过调试器并观察session[:return_to]设置,但在我登录并after_sign_in_path_for(resource) , session[:return_to]为空。 如何在登录中保留return_to变量? 我正在运行Rails 3.2.1和Devise 2.1.2

Rails设计注册表单不接受自定义用户名字段

我正在尝试为我的设计安装添加一个用户名,一个Railscast插曲。 我已将该字段添加到我的用户模型中,但是当我尝试使用用户名创建新用户时,表单操作会一直尝试将空值传递给我的数据库,这会引发错误。 这是我的用户模型的架构: create_table “users”, :force => true do |t| t.string “username”, :null => false t.string “email”, :default => “”, :null => false t.string “encrypted_password”, :limit => 128, :default => “”, :null => false t.string “password_salt”, :default => “”, :null => false t.string “reset_password_token” t.string “remember_token” t.datetime “remember_created_at” t.integer “sign_in_count”, :default => 0 t.datetime “current_sign_in_at” […]

更改Rails会话cookie域而不记录用户

我正在使用Rails 4.2.2(使用Devise 3.4.1)并且正在将cookie_store域从www.boundless.dev更改为.boundless.dev,以便在所有子域中共享相同的会话(单点登录) 。 Boundless::Application.config.session_store :cookie_store, key: ‘_boundless_session’, domain: ‘.boundless.dev’ 如果我单独做这个改变。 返回该站点的现有登录用户最终将获得2个_boundless_session cookie,一个使用domain _boundless_session ,另一个使用www.boundless.dev。 不知怎的,这使得登出不可能。 是否可以在不将所有用户从站点中注销的情况下进行此更改? 我以为我能够在我的ApplicationController中编写一个方法作为before_filter来删除会话cookie并将其替换为.boundless.dev中的一个新的,但它不起作用,我怀疑它有一些东西给我使用remember_user_token cookie。 def update_session_cookie_domain session_cookie = cookies[‘_boundless_session’] cookies.delete(‘_boundless_session’, domain: ‘www.boundless.dev’) cookies[‘_boundless_session’] = { value: session_cookie, domain: ‘.boundless.dev’ } end