My appllication uses a “Video” table. I have a video_controller and
associated video model
The video_controller requirs the user to login to the system.
class VideoController < ApplicationController
before_filter :login_required
When I initially wrote code for the Video model, I assumed that only
authenticated users would read, write Video records. Hence, I’ve got
code in the model such as:
@dir = ‘public/uploaded_videos’ + “/” + User.current_user.id
The above works fine when a logged in user accesses video functions on
the site.
Now, I want to display a list of videos on the Index/home page of the
web application. Users who access the web page don’t need to log in to
the system.
I created a home_controller with an index method.
def index
@videos = Video.find(:all, :conditions => [“public = 0”], :select =>
[‘id, file_name, file_size,thumbnail’])
end
Whenever, this method is executed, RoR makes a call to the video.rb
file and fails on the following line:
@dir = ‘public/uploaded_videos’ + “/” + User.current_user.id
It’s failing because User.current_user.id is null. This value is only
populated when a user logs into the system.
How can I get around this particular issue?