Permalink
Browse files

Add edit outputs

  • Loading branch information...
rociopaez committed Sep 16, 2014
1 parent a938e8b commit 5b5ad1a1bfbf584cbf129ec6c653ebd49ba36011
Showing with 59 additions and 0 deletions.
  1. +15 −0 routes/outputs.rb
  2. +42 −0 views/outputs/edit.mote
  3. +2 −0 views/outputs/index.mote
@@ -4,6 +4,21 @@ class Outputs < Cuba
render("outputs/new", title: "Output")
end

on(":id") do |id|
output = Output[id]

on post, param("output") do |params|
date = Date.new(params["date_year"].to_i, params["date_month"].to_i, params["date_day"].to_i)
output = output.update(date: date, scale: params["scale"], duration: params["duration"])

res.redirect("/outputs")
end

on get do
render("outputs/edit", title: "Edit Output", output: output)
end
end

on post, param("output") do |params|
date = Date.new(params["date_year"].to_i, params["date_month"].to_i, params["date_day"].to_i)
output = Output.create(date: date, scale: params["scale"], duration: params["duration"], user: current_user)
@@ -0,0 +1,42 @@
<h2>Edit Output</h2>

<form action="/outputs/{{output.id}}" method="POST">
<fieldset>
<label for="date">Date</label>
<select name="output[date_month]">
% 1.upto(12).each do |i|
<option{{ ' selected="selected"' if output.date.month == i }}>{{ i }}</option>
% end
</select>
<select name="output[date_day]">
% 1.upto(31).each do |i|
<option{{ ' selected="selected"' if output.date.day == i }}>{{ i }}</option>
% end
</select>
<select name="output[date_year]">
% this_year = Time.now.year
% start_year = this_year - 2
% start_year.upto(this_year).each do |i|
<option{{ ' selected="selected"' if output.date.year == i }}>{{ i }}</option>
% end
</select>

<label for="output[scale]">Scale of pain</label>
<select name="output[scale]">
% 1.upto(10).each do |i|
<option{{ ' selected="selected"' if output.scale == i }}>{{ i }}</option>
% end
</select>
<label for="output[duration]">Duration</label>
<select name="output[duration]">
<option value="30"{{ ' selected="selected"' if output.duration == 30 }}>30 min</option>
<option value="60"{{ ' selected="selected"' if output.duration == 60 }}>1 hour</option>
<option value="120"{{ ' selected="selected"' if output.duration == 120 }}>2 hour</option>
<option value="240"{{ ' selected="selected"' if output.duration == 240 }}>4 hours</option>
<option value="480"{{ ' selected="selected"' if output.duration == 480 }}>8 hours</option>
<option value="1440"{{ ' selected="selected"' if output.duration == 1440 }}>All Day</option>
</select>
</fieldset>

<input type="submit" value="Update">
</form>
@@ -9,6 +9,7 @@
<th>Date</th>
<th>Duration</th>
<th>Scale</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@@ -17,6 +18,7 @@
<td>{{output.date}}</td>
<td>{{output.duration}}</td>
<td>{{output.scale}}</td>
<td><a href="/outputs/{{output.id}}">Edit</a></td>
</tr>
% end
</tbody>

0 comments on commit 5b5ad1a

Please sign in to comment.