Forum: Ruby on Rails Executing a model from two different controllers - one contr

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
B71a865853854889813e9651d6cad19e?d=identicon&s=25 aquaflow (Guest)
on 2007-07-22 08:03
(Received via mailing list)
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' + "/" +

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'])


Whenever, this method is executed, RoR makes a call to the video.rb
file and fails on the following line:
@dir = 'public/uploaded_videos' + "/" +

It's failing because is null. This value is only
populated when a user logs into the system.

How can I get around this particular issue?
4c3acdc3d93f54cc7a7281780ec8a4ee?d=identicon&s=25 Shai Rosenfeld (shai)
on 2007-07-22 09:44
not that it makes any difference (you'll still solve the problem
regardless, but for general knowledge, where is the @dir statement being
called .. ?

either way, just add a 'unless User.current_user.nil?'

>     @dir = 'public/uploaded_videos' + "/" +

@dir = 'pub ... + unless User.current_user.nil?

should solve the problem, no?
E3513c4edd6810bb4b9914b58da2a2c3?d=identicon&s=25 Jamal Soueidan (jamal)
on 2007-07-22 10:28
aquaflow wrote:
Hence, I've got
> code in the model such as:
>     @dir = 'public/uploaded_videos' + "/" +

I just want to point out something, the code above should not be in the
model, but in the helpers.
B71a865853854889813e9651d6cad19e?d=identicon&s=25 aquaflow (Guest)
on 2007-07-26 00:45
(Received via mailing list)
Thank you. That worked perfectly.

I had previsouly tried using an if statement with the same condition:
#  if !(User.current_user.nil?)
#    DIRECTORY = 'public/uploaded_videos' + "/" +
#  end
It seemed like the if statement was being ignored.

@dir is being called from other methods within the model. I'm using it
ti define the destination file path for encoded video files.

On Jul 22, 12:44 am, Shai Rosenfeld <>
This topic is locked and can not be replied to.