Permalink
Browse files

Add New Input and save by user

  • Loading branch information...
rociopaez committed Sep 12, 2014
1 parent 5da5239 commit 0cfacd56d5fcee822effb4f305dafeeec2512a95
Showing with 39 additions and 12 deletions.
  1. +11 −1 routes/inputs.rb
  2. +23 −5 views/inputs/index.mote
  3. +5 −6 views/inputs/new.mote
@@ -4,8 +4,18 @@ class Inputs < Cuba
render("inputs/new", title: "New Input", types: Type.all)
end
on post, param("input") do |params|
date = Date.new(params["date_year"].to_i, params["date_month"].to_i, params["date_day"].to_i)
type = ::Type[params["type_id"]]
input = Input.create(date: date, type: type, user: current_user)
res.redirect("/inputs")
end
on get do
render("inputs/index", title: "Inputs", inputs: Input.all)
render("inputs/index", title: "Inputs", inputs: current_user.inputs) #esto se pasa al index
end
end
end
@@ -1,7 +1,25 @@
% inputs = params[:inputs]
<h2><a href="/inputs/new">New Input</a></h2>
<ul>
% params[:inputs].each do |inputs|
<li><a href="/inputs/{{ input.id }}">{{ input.type.category }} - {{ input.type.name }}</a></li>
% end
</ul>
<h2>Your Input Types record</h2>
<table>
<thead>
<tr>
<th>Date</th>
<th>Category</th>
<th>Name</th>
</tr>
</thead>
<tbody>
% inputs.each do |input|
<tr>
<td>{{input.date}}</td>
<td>{{input.type.category}}</td>
<td>{{input.type.name}}</td>
</tr>
% end
</tbody>
</table>
@@ -1,27 +1,27 @@
<h2>Migraine tracker - Inputs</h2>
<form action="/inputs" method="GET">
<form action="/inputs" method="POST">
<fieldset>
<label for="date">Date</label>
<select>
<select name="input[date_month]">
% 1.upto(12).each do |i|
<option{{ ' selected="selected"' if Time.now.month == i }}>{{ i }}</option>
% end
</select>
<select>
<select name="input[date_day]">
% 1.upto(31).each do |i|
<option{{ ' selected="selected"' if Time.now.day == i }}>{{ i }}</option>
% end
</select>
<select>
<select name="input[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="types">Types</label>
<select name="input[type]">
<select name="input[type_id]">
% params[:types].group_by { |type| type.category }.each do |category, types|
<optgroup label="{{ category }}">
% types.each do |type|
@@ -31,6 +31,5 @@
% end
</select>
</fieldset>
<input type="submit" value="send">
</form>

0 comments on commit 0cfacd5

Please sign in to comment.