views:

31

answers:

1

Ok I need some expert advise here....

I have a Photo Album that has_many Photos... Common stuff right?

Where I need expert advise is I want the use to click the desired photo album... and then see one photo at a time...

Should that all be happening in the PhotoAlbum Controller? that's how I have it now but it's getting messy as I want to add comments

Here's my current def show:

class PhotoAlbumsController < ApplicationController

    #Need to activate the Nav
        @space = Space.find(params[:space_id])

    @photoalbum = PhotoAlbum.find(params[:id])
    @photos = @photoalbum.photos.paginate :page => params[:page], :per_page => 1

    @photo = @photos

        @comments = @photoalbum.comments.roots.order("created_at DESC")

    respond_to do |format|
      format.html
    end

  end
.
.

Then in the View:

 <%= image_tag @photos.first.photo.url %>
 <%= render :partial => 'comments/index',:locals => {:commentable=> @photo.first,:comments => @comments}%>

Problem here is Photo comments is showing Comments for the Album, but recording it for the photo...

I want comments per Photo - Not Album.. and think maybe my controller setup is funky?

Thank you!

A: 

In your controller, you define @comments passed to the partial as the array of comments on your photo album:

@comments = @photoalbum.comments.roots.order("created_at DESC")

And then set the commentable object in your partial to the first photo in your album.

<%= render :partial => 'comments/index',:locals => {:commentable=> @photo.first,:comments => @comments}%>

So yes, you are listing an album's comments while posting new comments to a photo. Change @comments to comments for a photo.

ddagradi