-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path$
109 lines (94 loc) · 2.72 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
class NotesController < ApplicationController
before_filter :login_required
before_filter :get_step
#TODO remove show,new,edit and add image to note
def show
@notes = @step.note
respond_to do |format|
format.html
format.js { render( :partial => 'show',
:locals=>{:step=>@step, :note=>@note})}
end
end
def new
@note = Note.new
respond_to do |format|
format.html
format.js { render( :partial => 'new', :locals=>{:step=>@step,:note=>@note})}
end
end
def edit
@note = @step.note
respond_to do |format|
format.html
format.js { render( :partial => 'edit',:locals=>{:step=>@step,:note=>@note})}
end
end
def create
@note = Note.new( params[:note] )
@note.step = @step
respond_to do |format|
if @note.save
flash[:notice] = 'note saved'
format.html { redirect_to experiment_step_path(@experiment,@step) }
format.js { render(:partial=>'note',:locals=>{:step=>@step} )}
else
flash[:notice] = 'there was an error saving your note'
format.html { redirect_to experiment_step_path(@experiment,@step) }
format.js { render(:partial=>'note',:locals=>{:step=>@step} )}
end
end
end
def update
@note = @step.note
respond_to do |format|
if @note.update_attributes(params[:note])
flash[:notice] = 'Note changed'
format.html { redirect_to :back }
format.js { render(:partial => 'show',
:locals=>{:step=>@step, :note=>@note})}
else
flash[:notice] = 'There was an error updating your note'
format.html { redirect_to :back }
format.js { render(:partial => 'show',
:locals=>{:step=>@step, :note=>@note})}
end
end
end
def destroy
@note = @step.note
@note.destroy
respond_to do |format|
format.html { redirect_to :back }
format.js { render(:partial => 'new', :locals=>{:step=>@step, :note=>Note.new })}
end
end
############ actions for adding assests ##################
# action for uploading images to a note
require 'fileutils'
def upload
@note = @step.note
unless @note.image.blank?
@note.image.destroy
end
@image = Image.new(params[:note])
@note.image = @image
respond_to do |format|
if @image.save
format.html {redirect_to([@experiment,@step]) }
format.js { render(:partial => 'show',
:locals=>{:step=>@step, :note => @note})}
else
flash[:notice] = 'your photo did not save!'
format.html {redirect_to([@experiment,@step]) }
format.js {render(:partial => 'show',
:locals=>{:step=>@step, :note => @note} )}
end
end
end
private
def get_step
@step = Step.find(params[:step_id])
@experiment = @step.experiment
end
end