Forum: Ruby on Rails component/ajax variable access problem

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.
jeremy*pinnix (Guest)
on 2006-02-03 17:15
(Received via mailing list)
I'm trying to embed a little image gallery on each page. The photos
need to be different for each page. I just want to use ajax and let
them click on the photo and have it show the next image.

When the page loads, it shows the correct image. But when clicking on
it, it gives an error because it doesn't know what @images is anymore.

On the view for the home page:

<div id="easel"><%= render_component(:controller =>
'tiny_gallery/album', :action => 'show_photo', :params =>{:context=>
:home }) %></div>

Component Controller:

class TinyGallery::AlbumController < ActionController::Base


  def show_photo
      when params[:context] == :home
        @images = ['/images/1.jpg', '/images/2.jpg']
        @images = ['/images/test.gif']


Component View:

# p is always 0 when it comes in the first time...
photo = (params[:p]).to_i
next_photo = photo + 1
if !(photo == @images.length-1)

	<%= link_to_remote(image_tag(@images[next_photo], :size =>
"285x169"), :update =>'easel',
	:url => { :controller => '/tiny_gallery/album', :action =>
'show_photo', :params => { :context => :home, :p => next_photo }}) %>

<% else %>

	<%= link_to_remote(image_tag(@images[0], :size => "285x169"), :update
	:url => { :action => 'show_photo', :params => { :context => :home, :p
=> 0 }}) %>

<% end %>

When I change the component controller to not use the case statement,
it works just fine, but doesn't give me the option of showing
different photos based on which page it's being generated on...
This topic is locked and can not be replied to.