Comments (2)
Does the guest user serve any other purpose outside of the Ability class? If not you can just define an instance of User in memory instead of creating one to the database each time.
def initialize(user) user ||= User.new(...) end
However, if the guest user does need to be saved to the database and stored in the session then it should happen outside of the Ability class. This is because Ability knows nothing of the current request/session.
I recommend doing this in the current_user
method. Something like.
def current_user return @current_user if defined?(@current_user) @current_user = current_user_session && current_user_session.record @current_user ||= User.create!(....) # make guest user @current_user end
This way the guest user will only be created upon fetching the current user. Does this work for you?
from cancan.
Closing because I haven't heard back and I am assuming this resolved the problem.
from cancan.
Related Issues (20)
- User Interface HOT 2
- initialize method not called in production mode HOT 1
- show and edit are unauthorized on authorized (:manage) object HOT 1
- Called user model an alternative name
- PROJECT DISCONTINUED. STOP CREATING ISSUES AND GOTO CANCANCAN INSTEAD HOT 5
- lear
- CanCan::AuthorizationNotPerformed in AdminPanel::DashboardController#index HOT 1
- CanCan::AccessDenied exception HOT 1
- param is missing or the value is empty: activities HOT 1
- Role Infinite loop HOT 1
- CanCan is not allowing to initialize 2 users to have access to resources. Only one works at a time HOT 1
- Is CanCan being actively developed? HOT 2
- Question: How to load through parent of nested HOT 1
- How to differentiate permissions between admin/users_controller and users_controller
- Different exception messages for same pair of actions and subject
- Ability with conditions array behaving strangely for single objects
- before_filter deprecated
- Not loading expected results on :index action
- Update load_and_authorize_resource! "routing error before_filter" HOT 1
- Undefined Method exception when block is passed with curly braces
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cancan.