I'm working through "Learning Rails by Example" tutorial by Michael Hartl(11.33).The relevant code is:
class PagesController < ApplicationController
def home
@title = "Home"
if signed_in?
@micropost = Micropost.new
@feed_items = current_user.feed.paginate(:page => params[:page])
end
end
class User < ActiveRecord::Base
def feed
Micropost.all(:conditions => ["user_id = ?", id])
end
module SessionsHelper
def sign_in(user)
user.remember_me!
cookies[:remember_token] = { :value => user.remember_token,
:expires => 20.years.from_now.utc }
self.current_user= user
end
def current_user=(user)
@current_user = user
end
def current_user
@current_user ||= user_from_remember_token
end
@feed_items is then rendered as a collection to "will_paginate" and everything works fine.
My problem is that I cannot understand how the current_user is passed to the "feed" method in the PagesController line ie
"@feed_items = current_user.feed.paginate(:page => params[:page])"
Any help will be greatly appreciated
Alan