clicks_controller.rb
2.11 KB
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
class ClicksController < ApplicationController
# GET /clicks
# GET /clicks.xml
def index
@clicks = Click.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @clicks }
end
end
# GET /clicks/1
# GET /clicks/1.xml
def show
@click = Click.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @click }
end
end
# GET /clicks/new
# GET /clicks/new.xml
def new
@click = Click.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @click }
end
end
# GET /clicks/1/edit
def edit
@click = Click.find(params[:id])
end
# POST /clicks
# POST /clicks.xml
def create
#authenticate
if signed_in?
p = params[:click].except(:sid).merge(:visitor_id => current_user.visitors.find_or_create_by_identifier(params[:click][:sid]).id)
@click = Click.new(p)
else
render :nothing => true and return
end
respond_to do |format|
if @click.save
flash[:notice] = 'Click was successfully created.'
format.html { redirect_to(@click) }
format.xml { render :xml => @click, :status => :created, :location => @click }
else
format.html { render :action => "new" }
format.xml { render :xml => @click.errors, :status => :unprocessable_entity }
end
end
end
# PUT /clicks/1
# PUT /clicks/1.xml
def update
@click = Click.find(params[:id])
respond_to do |format|
if @click.update_attributes(params[:click])
flash[:notice] = 'Click was successfully updated.'
format.html { redirect_to(@click) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @click.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /clicks/1
# DELETE /clicks/1.xml
def destroy
@click = Click.find(params[:id])
@click.destroy
respond_to do |format|
format.html { redirect_to(clicks_url) }
format.xml { head :ok }
end
end
end