Permalink
Browse files

Add edit inputs

  • Loading branch information...
rociopaez committed Sep 18, 2014
1 parent cd52120 commit 5dcf6e7f49e55266321d323ba6229fe0b6c4794a
Showing with 59 additions and 0 deletions.
  1. +17 −0 routes/inputs.rb
  2. +37 −0 views/inputs/edit.mote
  3. +5 −0 views/inputs/index.mote
@@ -4,6 +4,23 @@ class Inputs < Cuba
render("inputs/new", title: "New Input", types: Type.all)
end


on(":id") do |id|
input = Input[id]

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.update(date: date, type: type)

res.redirect("/inputs")
end

on get do
render("inputs/edit", title: "Edit Input", input: input, user: current_user, types: current_user.types)
end
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"]]
@@ -0,0 +1,37 @@
<h2>Edit Inputs</h2>

<form action="/inputs/{{input.id}}" method="POST">
<fieldset>
<label for="date">Date</label>
<select name="input[date_month]">
% 1.upto(12).each do |i|
<option{{ ' selected="selected"' if input.date.month == i }}>{{ i }}</option>
% end
</select>
<select name="input[date_day]">
% 1.upto(31).each do |i|
<option{{ ' selected="selected"' if input.date.day == i }}>{{ i }}</option>
% end
</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 input.date.year == i }}>{{ i }}</option>
% end
</select>

<label for="types">Types</label>
<select name="input[type_id]">
% params[:types].group_by { |type| type.category }.each do |category, types|
<optgroup label="{{ category }}">
% types.each do |type|
<option value="{{ type.id }}">{{ type.name }}</option>
% end
</optgroup>
% end
</select>

</fieldset>
<input type="submit" value="send">
</form>
@@ -9,6 +9,7 @@
<th>Date</th>
<th>Category</th>
<th>Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@@ -17,7 +18,11 @@
<td>{{input.date}}</td>
<td>{{input.type.category}}</td>
<td>{{input.type.name}}</td>
<td><a href="/inputs/{{input.id}}">Edit</a></td>
</tr>
% end
</tbody>
</table>


<!-- <td class="action"><a href="/types/edit">Edit</a> - <a href="###">Delete</a></td> -->

0 comments on commit 5dcf6e7

Please sign in to comment.