On Tue, Feb 22, 2011 at 1:18 PM, John Merlino <li...@ruby-forum.com> wrote:
> Hey all, > > I have this in my plugins directory: > > 1: <% if current_user && current_user.admin? %> > 2: <div class="blogAdminLinks"> > 3: <ul class="blogList"> > 4: <li class="blogListFirst"><%= link_to 'New Blog Post', > new_blog_post_path %></li> > > As you can see,it references current_user > > So I define current_user in User model as a global variable: > > cattr_accessor :current_user > > I application controller, I define who current user is: > > def current_user > @current_user = User.find(1) > > return @current_user if defined?(@current_user) > end > > It does appear that the method overrides the one in model, assuming the > one in model is a getter/setter. > > Nevertheless, when I make a reference to it in one of my views, I get > undefined error method. Any idea? > At the top of your controller, you'll want to add helper_method :current_user But I don't understand what the 'cattr_accessor :current_user' in your user model accomplishes; where or how will you use that? You aren't using it in the controller. What I'm saying is, you don't need that, and probably don't want it. :-) > > Thanks for response. > > -- > 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@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.