2011-03-28 6 views

답변

3

지금은 아주 간단한 접근 방식을 사용했는데 매우 잘 작동합니다. 바로 Array -field를 포함하십시오.

#app/models/image.rb 
class Image 
    include Mongoid::Document 
    include Mongoid::Timestamps 

    field :message, :type => String 
    field :tags, :type => Array 

    def self.images_for tag 
    Image.any_in(:tags => [tag]) 
    end 
end 

#routes.rb 
match "tag/:tag" => "images#tag" 

#/app/controller/images_controller.rb 
class ImagesController < ApplicationController 
    # GET /tag 
    # GET /tag.xml 
    def tag 
    @images = Image.images_for params[:tag] 

    respond_to do |format| 
     format.html { render "index" } 
     format.xml { render :xml => @images } 
    end 
    end 
end 

그래도 작동하지만 Image.any_in 맵/축소의 성능에 대해서는 여전히 조금 의심 스럽습니다. 그지도에 대한 더 나은 해결책이있을 수 있습니다/줄일 수 있지만 아직 그것을 찾지 못했습니다.

3

/지도에 대해 "확장"솔루션입니다.

관련 문제