This should be obvious - but I’m a long-time non-web app programmer and
new to rails.
I simply want to put something in a variable in one action and access it
in another.
It’s like this, I’m doing a simple photo gallery/managment app, and I
have two actions in my picture_controller:
The first one scans the picture directory and creates a new object in
the pictures table for each picture it finds. The work is all done in a
method in the Picture model which returns an array containing the new
picture objects.
The second method is a normal list method, but instead of getting it’s
data from the db, gets it from that scan method - because it only lists
newly found pictures. At least that’s the plan.
How do I pass the array found in the first action to the second one.
So in the action we have something like this:
def scan_directory
# new_pics is an instance variable I’m creating here - I want
# to access it in my other action to get only the new pictures.
# There’s nothing in the database record to indicate what’s new,
it’s
# just a question of which new pics I found when calling
scan_directory
@new_pics = Picture.load_directory(".")
flash[:notice] = “Original image directory was refreshed
#{@new_pics.length} new images found”
redirect_to :controller => ‘picture’, :action => ‘list_new_pictures’
end
def list_new_pictures
# Is this how I should use a paginator when my list is not from the
db?
# Note that I get an exception here, because @new_pics is always
nil!
@picture_pages = Paginator.new self, @new_pics.count, 12,
@params[‘page’]
@pictures = @new_pics
render :action => 'list'
end
So what am I doing wrong? Is it not right to expect that instance
variables to hold values across actions? Why not?
Should I be shoving the @new_pics array into one of the hashes that gets
passed back and forth between the view and controller?
Is my paginator correct?
any help appreciated