开发者

devise/cancan demo account

开发者 https://www.devze.com 2023-02-25 16:44 出处:网络
I\'m using devise/cancan for my app and everything is pretty sound -- provided a user creates an account and sig开发者_如何学JAVAns in.

I'm using devise/cancan for my app and everything is pretty sound -- provided a user creates an account and sig开发者_如何学JAVAns in.

What I'd like to do is allow a user to get started without creating an account. And then sign up if they want to actually save their work.

Has anybody come across this before? Should I be figuring out how to create dummy accounts with devise? Or allowing unauthorized users access to creating models in my app via CanCan?

I could go into detail about how I've been thinking about approaching this, but it feels like a pretty obvious use case that somebody has come up with a nice solution for.

Thanks in advance, Mike


If you go with creating dummy accounts, you would have to track the user somehow via a cookie and cache the values in that cookie in your db. Cancan does allow for guest accounts via the ability model. For example:

user ||= User.new # Guest user, for users who are not registered or don't have an account yet

Which is enough you to you started with applying permissions for non registered users. Note though, tracking by cookie alone is not very reliable and can lead to some type of security hazard (i.e. by means of cookie hijacking). User, one day, can also decide to clear out his cookies.

If need be, I would suggest letting the user do minimal interaction with a guest account and motivating the user to sign up / register with Devise as much as possible.

Hope that helps!


I actually am considering the same problem, I have a scheduling app that makes a calendar. To get over the problem I'm thinking that you use

user ||= User.new

Like was suggested above and using cookies to get the data to the database once the user creates an account. This would mean that you would not have to worry about clearing out cookies because they would create an account if they want to save data.

0

精彩评论

暂无评论...
验证码 换一张
取 消