Permalink
Browse files

Add new Output and save by user

  • Loading branch information...
rociopaez committed Sep 13, 2014
1 parent f150138 commit 0fe006340f38f8aa1b5cc78f27955ac3a6fc2fc5
Showing with 61 additions and 18 deletions.
  1. +18 −0 routes/outputs.rb
  2. +4 −3 routes/users.rb
  3. +23 −0 views/outputs/index.mote
  4. +16 −15 views/outputs/new.mote
@@ -0,0 +1,18 @@
class Outputs < Cuba
define do
on("new") do
render("outputs/new", title: "Output")
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"].to_i, duration: params["duration"].to_i, user: current_user)
res.redirect("/outputs")
end
on get do
render("outputs/index", title: "Outputs", outputs: current_user.outputs)
end
end
end
@@ -13,6 +13,10 @@ class Users < Cuba
run(Inputs)
end
on("outputs") do
run(Outputs)
end
on("profile") do
run(Profile)
end
@@ -25,8 +29,5 @@ class Users < Cuba
run(Types)
end
on("outputs") do
render("outputs/new", title: "Outputs")
end
end
end
@@ -0,0 +1,23 @@
% outputs = params[:outputs]
<h2><a href="/outputs/new">New Output</a></h2>
<h2>Your Output Types record:</h2>
<table>
<thead>
<tr>
<th>Date</th>
<th>Duration</th>
<th>Scale</th>
</tr>
</thead>
<tbody>
% outputs.each do |output|
<tr>
<td>{{output.date}}</td>
<td>{{output.duration}}</td>
<td>{{output.scale}}</td>
</tr>
% end
</tbody>
</table>
@@ -1,41 +1,42 @@
<h2>Migraine tracker - Outputs</h2>
<form action="/#####" method="GET">
<form action="/outputs" method="POST">
<fieldset>
<label for="date">Date</label>
<select>
<select name="output[date_month]">
% 1.upto(12).each do |i|
<option{{ ' selected="selected"' if Time.now.month == i }}>{{ i }}</option>
% end
</select>
<select>
<select name="output[date_day]">
% 1.upto(31).each do |i|
<option{{ ' selected="selected"' if Time.now.day == i }}>{{ i }}</option>
% end
</select>
<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 Time.now.year == i }}>{{ i }}</option>
% end
</select>
<label for="pain_scale">Scale of pain</label>
<select>
<label for="output[scale]">Scale of pain</label>
<select name="output[scale]">
% 1.upto(10).each do |i|
<option>{{ i }}</option>
% end
</select>
<label for="duration">Duration</label>
<select>
<option>30 min</option>
<option>1 hour</option>
<option>2 hour</option>
<option>2 a 4 hours</option>
<option>4 to 8 hours</option>
<option>All the day</option>
<label for="output[duration]">Duration</label>
<select name="output[duration]">
<option value="30">30 min</option>
<option value="60">1 hour</option>
<option value="120">2 hour</option>
<option value="240">4 hours</option>
<option value="480">8 hours</option>
<option value="1440">All Day</option>
</select>
</fieldset>
<input type="submit" value="send">
<input type="submit" value="send">
</form>

0 comments on commit 0fe0063

Please sign in to comment.