Hello,
I am setting up a Rails 2.0 project where i am using
acts_as_authenticated as my user ''manager''. I am trying to use
the
scope_out plugin to group users into a Account. In order for that to
work i need to use the current_user inside the User Model. The most
obvious approach would be to use the example below and set the current
user inside the application controller. However this is just not
working. My current_user accessor stays empty inside the User model. Is
this because i am running in development mode or is this a known Rails
2.0 issue. Do you guys know any alternatives.
class ApplicationController < ActionController::Base
before_filter do |c|
User.current_user = User.find(c.session[:user].id) unless
c.session[:user].nil?
end
end
class User < ActiveRecord::Base
cattr_accessor :current_user
end
http://agilewebdevelopment.com/plugins/scope_out
Thanx in advance
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 27 Mar 2008, at 11:26, Vincent Bakker wrote:> > Hello, > > I am setting up a Rails 2.0 project where i am using > acts_as_authenticated as my user ''manager''. I am trying to use the > scope_out plugin to group users into a Account. In order for that to > work i need to use the current_user inside the User Model. The most > obvious approach would be to use the example below and set the current > user inside the application controller. However this is just not > working. My current_user accessor stays empty inside the User model. > Is > this because i am running in development mode or is this a known Rails > 2.0 issue. Do you guys know any alternatives.Isn''t the thing in the session normally :user_id ? Fred> > > > class ApplicationController < ActionController::Base > before_filter do |c| > User.current_user = User.find(c.session[:user].id) unless > c.session[:user].nil? > end > end > > class User < ActiveRecord::Base > cattr_accessor :current_user > end > > > http://agilewebdevelopment.com/plugins/scope_out > > Thanx in advance > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 27 Mar 2008, at 11:26, Vincent Bakker wrote: > >> Is >> this because i am running in development mode or is this a known Rails >> 2.0 issue. Do you guys know any alternatives. > > Isn''t the thing in the session normally :user_id ? > > FredYes it is the user id, copied the example from somewhere else, but adjusted in it in my code to User.current_user = User.find(c.session[:user]) unless c.session[:user].nil? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This is one of these cases where I''d just advise not to use the scope_out plugin. I don''t know what you''re trying to do, but it feels wrong when your User model needs data from the session to function. Regards, Jan On 27 Mar 2008, at 12:49, Vincent Bakker wrote:> > Frederick Cheung wrote: >> On 27 Mar 2008, at 11:26, Vincent Bakker wrote: >> >>> Is >>> this because i am running in development mode or is this a known >>> Rails >>> 2.0 issue. Do you guys know any alternatives. >> >> Isn''t the thing in the session normally :user_id ? >> >> Fred > > Yes it is the user id, copied the example from somewhere else, but > adjusted in it in my code to > > User.current_user = User.find(c.session[:user]) unless > c.session[:user].nil? > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Seems like things could be better structured. Since you''re using
acts_as_authenticated you could:
class ApplicationController < ActionController::Base
include AuthenticatedSystem
before_filter :login_required, :set_current_user
protect
def set_current_user
User.current_user = self.current_user
end
end
I disagree slightly with Jan. Jan is right that this application
seems to be too tightly coupled to the Controller. scope_out,
however, still may be appropriate to your needs... but your
application of it does seem off.
On Mar 27, 7:41 am, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On 27 Mar 2008, at 11:26, Vincent Bakker wrote:
>
>
>
> > Hello,
>
> > I am setting up a Rails 2.0 project where i am using
> > acts_as_authenticated as my user ''manager''. I am
trying to use the
> > scope_out plugin to group users into a Account. In order for that to
> > work i need to use the current_user inside the User Model. The most
> > obvious approach would be to use the example below and set the current
> > user inside the application controller. However this is just not
> > working. My current_user accessor stays empty inside the User model.
> > Is
> > this because i am running in development mode or is this a known Rails
> > 2.0 issue. Do you guys know any alternatives.
>
> Isn''t the thing in the session normally :user_id ?
>
> Fred
>
>
>
> > class ApplicationController < ActionController::Base
> > before_filter do |c|
> > User.current_user = User.find(c.session[:user].id) unless
> > c.session[:user].nil?
> > end
> > end
>
> > class User < ActiveRecord::Base
> > cattr_accessor :current_user
> > end
>
> >http://agilewebdevelopment.com/plugins/scope_out
>
> > Thanx in advance
> > --
> > Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---