incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Lutterkort <lut...@redhat.com>
Subject Re: Question on image_url
Date Wed, 24 Aug 2011 22:30:29 GMT
On Wed, 2011-08-24 at 16:11 -0400, Tong Li wrote:
> deltacloud uses haml, in some of the haml file such as
> views/images/index.html.haml, a line of code looks like this
> 
> 
> 	= link_to image.id, image_url(image.id)
> 
> 	method link_to is defined in url_helper.rb, but I can not find where
> image_url is defined and how it can be made available so that haml file can
> use it. can any one shed some light?

This is part of the magic that rabbit does. When a collection :things is
set up, rabbit creates helpers, that basically amount to the following
Ruby code

        def things_url(params={})
                "/api/foos" + query_params(params)
        end
        
        def thing_url(id, params={})
            "/api/foos/#{id}" + query_params(params)
        end
        
        # For every operation OP in the collection that is
        # not :index or :show, e.g. for :destroy
        if OP is member operation
          def OP_thing_url(id, params={})
                foo_url(id, params)
          end
    else
      def OP_thing_url(params={})
        foos_url(params)
      end
    end

    def query_params(params)
      return "" if params.empty?
      "?" + params.keys.map { |k| "#{k}=#{params[k]}" }.join("&")
    end

David



Mime
View raw message