相册、照片 - 相册分页

发布于 2024-09-28 22:00:57 字数 949 浏览 2 评论 0原文

好吧,我在这里需要一些专家的建议...

我有一个相册,里面有很多照片...常见的东西对吧?

我需要专家建议的地方是我希望用户单击所需的相册...然后一次查看一张照片...

这一切都应该在相册控制器中发生吗?这就是我现在的样子,但它变得混乱,因为我想添加评论

这是我当前的默认显示:

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
.
.

然后在视图中:

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

这里的问题是照片评论正在显示相册的评论,但将其记录为照片......

我想要每张照片的评论 - 不是相册.. 并认为我的控制器设置可能很时髦?

谢谢你!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走过海棠暮 2024-10-05 22:00:57

在控制器中,您将传递给局部的 @comments 定义为相册上的评论数组:

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

然后将局部中的可评论对象设置为相册中的第一张照片。

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

所以,是的,您在对照片发布新评论的同时列出了相册的评论。将@comments 更改为照片的评论。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文