Scaffold Todo
This commit is contained in:
27
app/views/todos/_form.html.erb
Normal file
27
app/views/todos/_form.html.erb
Normal file
@@ -0,0 +1,27 @@
|
||||
<%= form_with(model: todo) do |form| %>
|
||||
<% if todo.errors.any? %>
|
||||
<div style="color: red">
|
||||
<h2><%= pluralize(todo.errors.count, "error") %> prohibited this todo from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% todo.errors.each do |error| %>
|
||||
<li><%= error.full_message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div>
|
||||
<%= form.label :name, style: "display: block" %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= form.label :description, style: "display: block" %>
|
||||
<%= form.textarea :description %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
12
app/views/todos/_todo.html.erb
Normal file
12
app/views/todos/_todo.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<div id="<%= dom_id todo %>">
|
||||
<div>
|
||||
<strong>Name:</strong>
|
||||
<%= todo.name %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<strong>Description:</strong>
|
||||
<%= todo.description %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
2
app/views/todos/_todo.json.jbuilder
Normal file
2
app/views/todos/_todo.json.jbuilder
Normal file
@@ -0,0 +1,2 @@
|
||||
json.extract! todo, :id, :name, :description, :created_at, :updated_at
|
||||
json.url todo_url(todo, format: :json)
|
||||
12
app/views/todos/edit.html.erb
Normal file
12
app/views/todos/edit.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<% content_for :title, "Editing todo" %>
|
||||
|
||||
<h1>Editing todo</h1>
|
||||
|
||||
<%= render "form", todo: @todo %>
|
||||
|
||||
<br>
|
||||
|
||||
<div>
|
||||
<%= link_to "Show this todo", @todo %> |
|
||||
<%= link_to "Back to todos", todos_path %>
|
||||
</div>
|
||||
16
app/views/todos/index.html.erb
Normal file
16
app/views/todos/index.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<p style="color: green"><%= notice %></p>
|
||||
|
||||
<% content_for :title, "Todos" %>
|
||||
|
||||
<h1>Todos</h1>
|
||||
|
||||
<div id="todos">
|
||||
<% @todos.each do |todo| %>
|
||||
<%= render todo %>
|
||||
<p>
|
||||
<%= link_to "Show this todo", todo %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= link_to "New todo", new_todo_path %>
|
||||
1
app/views/todos/index.json.jbuilder
Normal file
1
app/views/todos/index.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.array! @todos, partial: "todos/todo", as: :todo
|
||||
11
app/views/todos/new.html.erb
Normal file
11
app/views/todos/new.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<% content_for :title, "New todo" %>
|
||||
|
||||
<h1>New todo</h1>
|
||||
|
||||
<%= render "form", todo: @todo %>
|
||||
|
||||
<br>
|
||||
|
||||
<div>
|
||||
<%= link_to "Back to todos", todos_path %>
|
||||
</div>
|
||||
10
app/views/todos/show.html.erb
Normal file
10
app/views/todos/show.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<p style="color: green"><%= notice %></p>
|
||||
|
||||
<%= render @todo %>
|
||||
|
||||
<div>
|
||||
<%= link_to "Edit this todo", edit_todo_path(@todo) %> |
|
||||
<%= link_to "Back to todos", todos_path %>
|
||||
|
||||
<%= button_to "Destroy this todo", @todo, method: :delete %>
|
||||
</div>
|
||||
1
app/views/todos/show.json.jbuilder
Normal file
1
app/views/todos/show.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.partial! "todos/todo", todo: @todo
|
||||
Reference in New Issue
Block a user