- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试在我的实用程序中设置渐进式参与,人们无需注册即可使用,例如notepad.cc 和 jsfiddle.net 以及我计划在用户“写入”应用程序时为用户创建一个 guest 用户(使用 Devise)。
我在 Devise wiki 上找到了这个指南 https://github.com/plataformatec/devise/wiki/How-To:-Create-a-guest-user它显示了如何在浏览器 session 期间创建访客用户。我想要的是用户在后续访问中继续使用相同的访客帐户,直到他注册为止,也许当我推出更多功能的订阅计划时。
如何修改指南中的内容以实现此目的?
上面链接的指南中的代码:
# file: app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
# if user is logged in, return current_user, else return guest_user
def current_or_guest_user
if current_user
if session[:guest_user_id]
logging_in
guest_user.destroy
session[:guest_user_id] = nil
end
current_user
else
guest_user
end
end
# find guest_user object associated with the current session,
# creating one as needed
def guest_user
User.find(session[:guest_user_id].nil? ? session[:guest_user_id] = create_guest_user.id : session[:guest_user_id])
end
# called (once) when the user logs in, insert any code your application needs
# to hand off from guest_user to current_user.
def logging_in
end
private
def create_guest_user
u = User.create(:name => "guest", :email => "guest_#{Time.now.to_i}#{rand(99)}@email_address.com")
u.save(false)
u
end
end
并在 Controller 中使用它:
@thing.user = current_or_guest_user
@thing.save
最佳答案
在剃了一些牦牛毛之后,我设法让它开始工作。这是工作代码:
class ApplicationController < ActionController::Base
protect_from_forgery
# if user is logged in, return current_user, else return guest_user
def current_or_guest_user
if current_user
if cookies[:uuid]
logging_in # Look at this method to see how handing over works
guest_user.destroy # Stuff have been handed over. Guest isn't needed anymore.
cookies.delete :uuid # The cookie is also irrelevant now
end
current_user
else
guest_user
end
end
# find guest_user object associated with the current session,
# creating one as needed
def guest_user
User.find_by_lazy_id(cookies[:uuid].nil? ? create_guest_user.lazy_id : cookies[:uuid])
end
# called (once) when the user logs in, insert any code your application needs
# to hand off from guest_user to current_user.
def logging_in
# What should be done here is take all that belongs to user with lazy_id matching current_user's uuid cookie... then associate them with current_user
end
private
def create_guest_user
uuid = rand(36**64).to_s(36)
temp_email = "guest_#{uuid}@email_address.com"
u = User.create(:email => temp_email, :lazy_id => uuid)
u.save(:validate => false)
cookies[:uuid] = { :value => uuid, :path => '/', :expires => 5.years.from_now }
u
end
end
如果您能告诉我更好的方法,我会接受另一个答案。
关于ruby-on-rails - 逐步参与,持续的 guest 用户与 Devise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8267230/
最近我有兴趣加入一个开源的 p2p 文件共享项目。我对这个主题的了解不是那么具体,我的意思是我了解安全、网络、p2p 基础知识,但我仍然不知道从哪里开始同时了解全局和实际细节。简而言之,推荐的资源是什
自从百度发布超链接算法升级公告之后,看到很多SEO大神对于外链对排名的作用就更加讳莫如深,而作为个人站长,大家对于外链的看法各执一词。像高质量外链、外链作用、外链对排名的影响等等话题,各大论坛讨论的
老实说,这是一个家庭作业问题,但我已经浪费了好几个小时,而且无法正确解决。它返回错误数量的结果或错误的数据: 我需要选择参与指导电影和/或在电影中表演的每个人以及他们所做的次数,如果至少 5 次。 有
我只是想知道如何为我的应用程序激活 (RED) 东西。我在我的应用程序中添加了一个新的更新,看看是否有参与的复选标记,但没有。是否可能是 Apple 决定哪些应用“有资格”加入该计划? 提前致谢:)
在我的代码中我有这样的东西: struct SomeStruct { int test1; int test2; float test3; float test4; }; std::v
我有一个继承自 UIControl 的自定义类,用于获取触摸事件。它基本上是其他控件的集合,这些控件充当一个整体。我正在将我的应用程序从 xibs 转换为 Storyboard。除了这个之外,它基本上
我正在使用 expo 制作一个 React 应用程序,我想允许子元素出现在我的 TopicSection 元素中。我关注了this guide为了允许 JSX 元素中的子元素,并编写了以下代码。我尝试
根据 Uber 文档,应通过以下方式推荐新用户:“https://m.uber.com/sign-up?client_id=YOUR_CLIENT_ID ” 那么,有没有办法通过以下方式引用使用 oA
更新:这个问题至少通过 -XX:+UseCountedLoopSafepoints 和等于或高于 JDK 1.8.0_92 的 JVM 版本(使用 _161 测试)的组合粗略地解决了。 原创:包含 J
我有一个 Maven 项目,它编译为 webapp,具有标准 Maven war 布局。我正在尝试向同一个项目添加方面,但当部署为 Tomcat 上的 war 时,这些方面不会被触发。如果我将项目部署
现在 Facebook 会列出生日等事件的参与度,我想在我的网站上显示参与度。 有什么方法可以通过图形 API 让 friend 参与进来吗? 最佳答案 https://graph.facebook.
我正在安装 Engage! 我按照此处的安装说明进行操作:http://engagecsm.com/readme 我做的安装步骤: 添加互动!到应用程序的 Gemfile:gem 'engagecsm
对于以下实体关系结构,我正在努力弄清楚 LOAN 和 ITEM 实体之间的关系是否有效? LOAN 的弱实体使用 'loan_dateLeant' 的部分键和来自 CUSTOMER 和 ITEM 的主
我目前正在研究涉及 VBA 和 IE 的自动化流程。随着我的代码正在执行的多项操作,一切都与时俱进。问题是当我接近一个有 2 个下拉列表的部分时,在第一个下拉列表中做出某些选择后出现第二个下拉列表。
我有以下 Spring Integration 配置。我在这里所做的是dequeuing 来自主题的消息并在转换后将其发送到某个 HTTP 位置。 JMS 连接工厂 配置如下:
我正在使用 python-firebase在我的堆栈中记录点击次数和其他事件数据。它工作正常,但时不时地抛出这个堆栈跟踪: 'ConnectionError(MaxRetryError("HTTPSC
我是一名优秀的程序员,十分优秀!