Module: HasTrolleyControllerHelpers::UrlFor

Defined in:
lib/has_trolley_controller_helpers.rb

Instance Method Summary collapse

Instance Method Details

#url_for_order(options = { }) ⇒ Object

expects order either as instance variables or in options



28
29
30
31
32
33
34
35
36
# File 'lib/has_trolley_controller_helpers.rb', line 28

def url_for_order(options = { })
  trolley = options[:trolley] || @trolley
  trolley = @order.trolley if @order && trolley.blank?

  order = options[:order] || @order || trolley.selected_order
  trolley = order.trolley

  url_for [trolley.user, trolley, order]
end

#url_for_order_or_trolleyObject



38
39
40
41
42
43
44
45
46
# File 'lib/has_trolley_controller_helpers.rb', line 38

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

#url_for_trolley(options = { }) ⇒ Object

expects user in options or @user or trolley being set



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/has_trolley_controller_helpers.rb', line 9

def url_for_trolley(options = { })
  user = options[:user]
  trolley = options[:trolley] || @trolley || user.trolley

  if trolley.blank?
    user = @user
  else
    user = trolley.user
  end

  # 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