Skip to content

Commit

Permalink
allow plants to get their status modified via ui
Browse files Browse the repository at this point in the history
  • Loading branch information
one-m1nd committed Mar 4, 2024
1 parent 197f7b7 commit b4684e6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/views/plants/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<%= form.text_field :name %>
<%= collection_select(:plant, :family_id, Family.all.sort_by(&:name), :id, :name, prompt: true) %>
<%= collection_select(:plant, :genus_id, Genus.all.sort_by(&:name), :id, :name, prompt: true) %>
<%= collection_select(:plant, :status_id, Status.all, :id, :name, prompt: true) %>

<div class="inline">
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
Expand Down
5 changes: 5 additions & 0 deletions app/views/plants/_plant.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<td class="border border-slate-900">Genus</td>
<td class="border border-slate-900"><%= @plant.genus.name %></td>
</tr>

<tr>
<td class="border border-slate-900">Status</td>
<td class="border border-slate-900"><%= @plant.status.name %></td>
</tr>
</tbody>
</table>
</div>
4 changes: 4 additions & 0 deletions app/views/plants/_plant.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ end

json.family do
json.extract! plant.family, :id, :name, :created_at, :updated_at
end

json.status do
json.extract! plant.status, :id, :name, :created_at, :updated_at
end
6 changes: 5 additions & 1 deletion app/views/plants/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<% end %>

<div class="flex justify-between items-center">
<h1 class="font-bold text-4xl"> <%= @plants.length %> Plants</h1>
<h1 class="font-bold text-4xl"> <%= @plants.length %> Plants </h1>
<h2> <%= @plants.select { |plant| plant.status.id == 1 }.length %> Alive </h2>
<h2> <%= @plants.select { |plant| plant.status.id == 2 }.length %> Dead </h2>
<%= link_to 'New plant', new_plant_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
</div>

Expand All @@ -14,6 +16,7 @@
<th>Name</th>
<th>Family</th>
<th>Genus</th>
<th>Status</th>
<th>URL</th>
</tr>
</thead>
Expand All @@ -23,6 +26,7 @@
<td class="border border-slate-900"><%= plant.name %></td>
<td class="border border-slate-900"><%= plant.family.name %></td>
<td class="border border-slate-900"><%= plant.genus.name %></td>
<td class="border border-slate-900"><%= plant.status.name %></td>
<td class="border border-slate-900">
<a href="<%= plant_url(plant) %>">Show</a>
</td>
Expand Down

0 comments on commit b4684e6

Please sign in to comment.