Tag: 设计

如何存储新用户的推荐位置? 使用Rails + Devise

我有一个使用设计的rails应用程序。 我很想知道,在User表中是否有可能以某种方式跟踪新用户来自哪里,HTTP引用者? 我想知道哪些来自Facebook,Twitter,LinkedIn,Google+以跟踪病毒循环。 有任何想法吗? 看到有人这样做吗? 可能? 它应该放在rails应用程序中的哪个位置? 还是很新的。 谢谢

使用方法:设计after_sign_up_redirect?

我试着按照这里的说明( GitHub Devise Wiki ),但它不适合我。 我想在用户注册后让Devise重定向到/ welcome。 我创建了一个注册控制器,但它永远不会进入视图。 我在这做错了什么? Ruby 1.9.2 Rails 3.1.0.rc4 Devise 1.4.2 谢谢 更新: 由于某种原因,未触发after_sign_up_path_for但触发了after_sign_in_path_for 。 我仍然想让after_sign_up_path_for工作 _app /控制器/ registrations_controller.rb_ class RegistrationsController < Devise::RegistrationsController protected def after_sign_up_path_for(resource) welcome_path end end 这是我的config / routs.rb MyApp::Application.routes.draw do devise_for :users root :to => ‘pages#home’ match “/users”, :to => “users#all” match “/users/:id”, :to => “users#show”, :as […]

如何将Devise和ActiveAdmin用于相同的用户模型?

我有ActiveAdmin和Devise与用户合作。 我想使用Devise登录具有相同用户模型的常规非管理员用户。 我怎样才能做到这一点? (我想在User模型中只为管理员设置一个admin标志。)我尝试将第二行添加到routes.rb devise_for :users, ActiveAdmin::Devise.config devise_for :users 但是当我试图列出路线时,它给出了一个错误 >rake routes DL is deprecated, please use Fiddle rake aborted! ArgumentError: Invalid route name, already in use: ‘new_user_session’ You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with […]

在为Devise中的用户做手动sign_in时,你怎么设置记住我是?

在Devise中 ,我正在以这样的方式登录我的用户: sign_in_and_redirect(:user, user) 在默认登录页面中,有一个用户可以选择的复选框,以便他们在返回站点时不必再次登录。 但是,当您使用sign_in_and_redirect(:user, user)行登录时,我无法确定如何将该参数设置为yes。 有谁知道怎么样? 谢谢阅读。

Chrome扩展程序+设计+ Rails应用程序 – 从扩展程序进行经过身份validation的请求?

我正在构建一个chrome扩展,它可以直接从浏览器创建联系人,而无需转到我的设计驱动的rails应用程序本身。 联系人#Create需要身份validation,所以我想知道如何从扩展程序发送经过身份validation的请求。 我已经启用了设计TokenAuthenticatable ,所以我的用户有一个authtoken。 我在我的扩展程序js中写了一个方法,发布到我的rails应用程序的联系人#create action。 为了测试,我只是硬编码了我自己的身份validation令牌,这似乎有效。 但是扩展如何为用户访问auth令牌? 将此令牌存储到cookie中似乎不正确/安全。 我想我应该使用chrome.cookies访问并以某种方式使用我的应用程序的会话信息。 但我这里只得到一个sessionID。 任何帮助赞赏!

carrierwave,Excon :: Errors :: MovedPermanently in RegistrationsController #update error

我一直试图让carrierwave与amazon s3合作。 代替 storage :s3 我有 storage :fog 将其更改为存储:s3立即出错 https://stackoverflow.com/questions/10629827/carrierwave-cant-convert-nil-into-string-typeerror-when-using-s3 所以我把它改成了存储:像下面的rdoc所说的雾。 http://rubydoc.info/gems/carrierwave/frames 然而,当我尝试上传图像时,我得到了这个疯狂的错误。 我正在使用设计gem。 我的完整堆栈跟踪是 Excon::Errors::MovedPermanently in RegistrationsController#update Excon::Errors::MovedPermanently (Expected(200) Actual(301 Moved Permanently) request => {:connect_timeout=>60, :headers=>{“Content-Length”=>95472, “Content-Type”=>”image/jpeg”, “x-amz-acl”=>”private”, “Cache-Control”=>”max-age=315576000”, “Date”=>”Thu, 17 May 2012 05:28:55 +0000”, “Authorization”=>”AWS AKIAIN6SC3YSGBSUKV4Q:kZOG9mG01jYn48ImFMYbgxAAQRk=”, “Host”=>”user.a.777.s3-eu-west-1.amazonaws.com:443″}, :instrumentor_name=>”excon”, :mock=>false, :read_timeout=>60, :retry_limit=>4, :ssl_ca_file=>”/Users/sasha/.rvm/gems/ruby-1.9.3-p125/gems/excon-0.13.4/data/cacert.pem”, :ssl_verify_peer=>true, :write_timeout=>60, :host=>”user.a.777.s3-eu-west-1.amazonaws.com”, :path=>”/uploads%2Fuser%2Fimage%2F59%2Fidea.jpg”, :port=>”443″, :query=>nil, :scheme=>”https”, :body=>#, :expects=>200, :idempotent=>true, :method=>”PUT”} […]

Rails 3覆盖Devise会话控制器

我需要在登录过程中重写Devise会话控制器(Rails 3.0.9,Ruby 1.9.2,Devise 1.3.4),我试过这个没有任何影响 class SessionsController < Devise::SessionsController # GET /resource/sign_in def new resource = build_resource clean_up_passwords(resource) respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new } end end 想法? 编辑如答案所示,我还需要改变路线。 另外,我还需要复制视图。 这里有更好的解释http://presentations.royvandewater.com/authentication-with-devise.html#8 我的自定义策略: devise.rb config.warden do |manager| manager.strategies.add(:custom_strategy) do def authenticate! … authenticate against 3rd party API… if res.body =~ /success/ u = User.find_or_initialize_by_email(params[:user][:email]) if u.new_record? u.save end success!(u) […]

无法使用Devise批量分配受保护的属性以创建has_many嵌套模型

我已经看过RailsCast,另一个嵌套属性video,很多SOpost,并与此争吵了一段时间,但我仍然无法弄明白。 我希望它有点小。 我有两个模型, User (由Devise创建)和Locker (又名产品愿望清单),我正在尝试为User注册时创建一个Locker 。 我的登录表单有一个新的Locker名称字段(恰当地称为:name ),我试图分配给在新用户注册时创建的锁定器。 我所遇到的只有: WARNING: Can’t mass-assign protected attributes: locker 我已经在我的两个模型中尝试了accepts_nested_attributes和attr_accesible每个组合,但仍然attr_accesible 。 我可以从日志中看到它正在由Devise #create方法处理,我知道Devise不够聪明,无法创建我想要的模型:) 这是我的两个模型的相关部分: # user.rb class User :lockers # Model nesting access accepts_nested_attributes_for :lockers end 和 # locker.rb class Locker :lockups attr_accessible :name, :description end # lockers_controller.rb (create) @locker = current_user.lockers.build(params[:locker]) @locker.save 我假设我需要覆盖Devise的create方法以某种方式让它工作,但我对rails非常新,并且我已经习惯了黑盒子“神奇”的本质。 如果有人能帮助我,我会非常感激。 已经花了太多时间在这上面,因为它是:) 编辑:我意识到我在我的问题中省略了一些东西。 我的Locker模型有三个属性 […]

在rails + doorkeeper中使用grant_type = password在访问令牌请求中强制设置client_id和secret

目前我在使用doorkeeper的rails中的请求中有一个访问令牌api,其中包含用户名,密码和grant_type作为密码。 但我需要将client_id和secret作为请求中的必填字段。 我怎样才能做到这一点。 任何人都可以帮助做到这一点。 在我的doorkeeper.rb配置文件中, resource_owner_from_credentials do |routes| #client = OAuth2::Client.new(request.params[:client_id], request.params[:client_secret], site: “http://localhost:3000/”) #auth_url = client.auth_code.authorize_url(:redirect_uri => “urn:ietf:wg:oauth:2.0:oob”) request.params[:user] = {:email => request.params[:username], :password => request.params[:password]} request.env[“devise.allow_params_authentication”] = true request.env[“warden”].authenticate!(:scope => :user) end 我想使用用户凭据进行身份validation,并且还希望将client_id和secret设为必填字段。 如果缺少client_id和secret,我想显示一条消息。

无法使用after_inactive_sign_up_path_for进行路由

我重写了RegistrationController my_devise / Registration控制器我重写了以下方法: def after_inactive_sign_up_path_for(resource)awaiting_confirmation_path 结束 我的RegistrationController中还有一个名为的新方法:def awaiting_confirmation(resource)do tuff …. 结束 我的路由文件看起来像这样: devise_for:accounts,:controllers => {:registrations =>“my_devise / registrations”} 资源:注册匹配“awaiting_confirmation”=>“注册#awaiting_confirmation”结束 我收到一条错误消息:没有路由匹配{:action =>“awaiting_confirmation”,:controller =>“registrations”} 我究竟做错了什么?