- Recent
- Popular
- Tags (0)
- Subscribers (1)
- Help us Beta!December 17 2007
-
A lot has been going on behind the scenes at NoteSake since our launch earlier this year. We are now in the midst of our first major build and are excited about the new features we will be offering. Coming January 2008, NoteSake.com will offer some features that we had always wanted to include, but steered clear of until we had them laid out perfectly. We are so excited about these changes that we would like to give our users the opportunity to check out the new features before the build is actually finalized. We are officially opening our staging site to the public: http://humpty.notesake.com. Aside from granting a sneak peak of the new site, the development team at NoteSake is looking for feedback and criticism from our dedicated users. Your opinion is respected and appreciated, so do not hesitate to tell us what you think.
Upon arriving at the Humpty site, there are two options for logging in: a new user account can be created or a user may visit only as a guest. It is preferred that a new account be created, but if you would rather not, simply input “guest” for both the user ID and password. The guest account is restricted from saving any data, so it may be in your best interest to create a new account.
As it is, NoteSake.com is pretty, but fails to leave the developers much room to conveniently make additions to the experience. To accommodate the need to implement changes that are made
- Access current user in modelsNovember 29 2007
-
So I recently have been working on something for NoteSake that requires me to access the current logged in user in a model. The problem with this is that it is saved in a session which is then gotten in a before_filter in the controllers. We all know you can’t access session’s in models (and even if you could it really is just not very lady like).
So I searched and I scrounged and I hunted. And then I found this little gem on the rails wiki. It describes how to add a created_by and updated_by column to your tables. It is full of activerecord goodness so I would definatly suggest taking a look.
Anyways here is the short and easy way to do this. It is also pretty nice and DRY (we all love keywords right?).
In this example I am using the code from NoteSake which stores the current_user in the User model. This can be done with anything though.
So first off lets let make it so we can hold this in the model
cattr_accessor :current_userHere we do something tricky. We use cattr_accessor instead of its well known brother attr_accessor. What this does is create a attribute which is accessable to the entire class. It is implemented in ActiveSupport.
Okay so nothing that m
