From 5dcf6e7f49e55266321d323ba6229fe0b6c4794a Mon Sep 17 00:00:00 2001 From: Rocio Paez Date: Thu, 18 Sep 2014 14:54:49 -0500 Subject: [PATCH] Add edit inputs --- routes/inputs.rb | 17 +++++++++++++++++ views/inputs/edit.mote | 37 +++++++++++++++++++++++++++++++++++++ views/inputs/index.mote | 5 +++++ 3 files changed, 59 insertions(+) create mode 100644 views/inputs/edit.mote diff --git a/routes/inputs.rb b/routes/inputs.rb index 2e56852..5d93ee1 100644 --- a/routes/inputs.rb +++ b/routes/inputs.rb @@ -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"]] diff --git a/views/inputs/edit.mote b/views/inputs/edit.mote new file mode 100644 index 0000000..85b2f4c --- /dev/null +++ b/views/inputs/edit.mote @@ -0,0 +1,37 @@ +

Edit Inputs

+ +
+
+ + + + + + + + +
+ +
diff --git a/views/inputs/index.mote b/views/inputs/index.mote index 94142d3..de9a6f6 100644 --- a/views/inputs/index.mote +++ b/views/inputs/index.mote @@ -9,6 +9,7 @@ Date Category Name + Actions @@ -17,7 +18,11 @@ {{input.date}} {{input.type.category}} {{input.type.name}} + Edit % end + + +