Permalink
Browse files

Edit and create types

  • Loading branch information...
rociopaez committed Sep 25, 2014
1 parent e73309a commit ed6a498308a559ce62794da8aeb56a13b1774164
Showing with 24 additions and 22 deletions.
  1. +2 −0 config/default_types.yml
  2. +16 −13 routes/types.rb
  3. +5 −8 views/types/edit.mote
  4. +1 −1 views/{types.mote → types/index.mote}
@@ -24,3 +24,5 @@
name: "Exedrin"
- category: "Medication"
name: "Aspirin"
- category: "Other"
name: "other"
@@ -4,28 +4,31 @@ class Types < Cuba
render("types/new", title: "New Type")
end

on("edit") do
render("types/edit", title: "Edit Type")
end
on(":id") do |id|
type = Type[id]

on post, param("type") do |params|
create_type = CreateType.new(params)
if create_type.valid?
Type.create(create_type.slice(:category, :name))
on post, param("type") do |params|
type.update(category: params["category"], name: params["name"])
res.redirect("/types")
end
end

on("types/new") do
on post, params("type") do |params|
create_type = CreateType.new(params)
Type.create(category: type_attributes["category"], name: type_attributes["name"], user_id: user.id)
on get do
render("types/edit", title: "Types Edit", type: type)
end
end

on post, param("type") do |params|
Type.create(category: params["category"], name: params["name"], user_id: current_user.id)
res.redirect("/types")
end

on default do
render("types", title: "Types", user: current_user)
render("types/index", title: "Types", user: current_user)
end
end
end


# on("edit") do
# render("types/edit", title: "Edit Type")
# end
@@ -1,19 +1,16 @@
<h2>Edit your type</h2>

<form action="/types" method="POST">
<form action="/types/{{ type.id }}" method="POST">
<fieldset>
<label for="type[category]">Category</label>
<select name="type[category]">
<option>Food</option>
<option>Drink</option>
<option>Symptoms</option>
<option>Body Changes</option>
<option>Medication</option>
<option>Other</option>
% DEFAULT_TYPES.map { |t| t["category"] }.uniq.each do |category|
<option{{ ' selected="selected"' if type.category == category }}>{{ category }}</option>
% end
</select>

<label for="type[name]">Name</label>
<input type="text" name="type[name]">
<input type="text" name="type[name]" value="{{ type.name }}">
</fieldset>

<input type="submit" value="Save">
@@ -17,7 +17,7 @@
<tr>
<td>{{type.category}}</td>
<td>{{type.name}}</td>
<td class="action"><a href="/types/edit">Edit</a> - <a href="###">Delete</a></td>
<td class="action"><a href="/types/{{type.id}}/edit">Edit</a> - <a href="###">Delete</a></td>
</tr>
% end
</tbody>

0 comments on commit ed6a498

Please sign in to comment.