Component/ajax variable access problem

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:

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

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, :stuck_out_tongue: => next_photo }}) %>

<% else %>

<%= link_to_remote(image_tag(@images[0], :size => "285x169"), :update

:url => { :action => ‘show_photo’, :params => { :context => :home, :stuck_out_tongue:
=> 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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs