/
public_listings_controller.rb
104 lines (88 loc) · 2.94 KB
/
public_listings_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
class PublicListingsController < PublicController
def index
raise Exception.new("forced error to test error page")
end
# GET /listings/new/offer
def offer
@listing = Listing.new
@listing.driver = true
@listing.board = @board
render :template => "public/new"
end
# GET /listings/new/wanted
def wanted
@listing = Listing.new
@listing.driver = false
@listing.board = @board
render :template => "public/new"
end
# GET /listings/1/edit
def edit
@listing = Listing.first!(:id => params[:id], :board => @board)
render :template => "public/removal"
end
# POST /listings/1/reminder
def reminder
@listing = Listing.first!(:id => params[:id], :board => @board)
# @listing.board.venue has no lang_code state set !!!
url = @venue.iframe_url
if url.blank?
if @venue.password
# TODO maybe it is just the other url as well ?!
url = url_for(:controller => :listings,
:action => :edit)
else
url = url_for(:id => @listing.id,
:venue => @venue.name,
:board_id => @board.id,
:lang => @lang.code,
:controller => :public_listings,
:action => :edit)
end
end
logger.debug "listing url: " + url if logger && logger.debug?
Mailer.deliver_remind(@listing, url)
render :template => "public/reminder_sent"
end
# POST /listings
# POST /listings.xml
def create
date = DateTime.civil(params[:listing].delete("ridedate(1i)").to_i, params[:listing].delete("ridedate(2i)").to_i, params[:listing].delete("ridedate(3i)").to_i)
@listing = Listing.new(params[:listing])
@listing.ridedate = date
@listing.board = @board
@listing.reset_password
if !Listing.first(:board_id => @listing.board.id,
:name => @listing.name,
:location => @listing.location,
:email => @listing.email,
:ridedate => @listing.ridedate,
:driver => @listing.driver).nil?
render :template => "public/exists"
elsif @listing.save
url = @venue.iframe_url
if url.blank?
url = url_for(:venue => @venue.name,
:id => @board.id,
:lang => @lang.code,
:controller => :public_boards,
:action => :show)
end
Mailer.deliver_confirm(@listing, url, @lang.code)
render :template => "public/created"
else
render :template => "public/new"
end
end
# DELETE /listings/1
# DELETE /listings/1.xml
def destroy
@listing = Listing.first(:id => params[:id], :board => @board)
if @listing && params[:password] == @listing.password
@listing.destroy
render :template => "public/confirmed"
else
render :template => "public/not_authorized"
end
end
end