Sha256: cb0e576dbb8ff28c11694585cea03ca4528faefb05e1fdd40ecd1fe8be756e29

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

module HasTrolleyControllerHelpers
  def self.included(klass)
    klass.send :helper_method, :url_for_trolley
    klass.send :include, UrlFor
  end
  
  module UrlFor
    # expects user in options or @user or trolley being set
    def url_for_trolley(options = { })
      user = options[:user] || @user
      user = @trolley.user if @trolley && user.blank?

      trolley = options[:trolley] || @trolley || user.trolley

      # TODO: Hack, not sure if this is 2.3.5 bug or my ignorance
      # but url_for returns marshalled trolley, in addition to correct url
      url = url_for(:user_id => user.id,
                    :controller => :trolleys,
                    :action => :show).split(".%23%")[0]
    end

    # expects order
    # either as instance variables or in options
    def url_for_order(options = { })
      trolley = options[:trolley] || @trolley
      trolley = @order.trolley if @order && trolley.blank?

      order = options[:order] || @order || trolley.selected_order
      
      url_for [trolley.user, trolley, order]
    end

    def url_for_order_or_trolley
      raise unless @order

      if @order.user == current_user
        url_for_trolley :trolley => @order.trolley
      else
        url_for_order
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trollied-0.1.2 lib/has_trolley_controller_helpers.rb
trollied-0.1.1 lib/has_trolley_controller_helpers.rb
trollied-0.1.0 lib/has_trolley_controller_helpers.rb