Skip to content

Commit

Permalink
edit views and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Hicks committed Jan 26, 2023
1 parent 25060f9 commit af9560b
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 80 deletions.
35 changes: 8 additions & 27 deletions app/controllers/funds_controller.rb
Original file line number Diff line number Diff line change
@@ -1,49 +1,30 @@
class FundsController < ApplicationController
before_action :set_fund, only: %i[ show edit update destroy ]
before_action :confirm_admin_user
before_action :set_fund, only: %i[show edit update destroy]
rescue_from ActiveRecord::RecordNotFound, with: -> { head :bad_request }

# GET /funds
def index
@funds = Fund.all
@funds = Fund.all.sort_by { |f| [f.name] }
end

# GET /funds/1
def show
@fund
end

# GET /funds/new
def new
@fund = Fund.new
end

# GET /funds/1/edit
def edit
end

# POST /funds
def create
@fund = Fund.new(fund_params)

if @fund.save
redirect_to @fund, notice: "Fund was successfully created."
else
render :new, status: :unprocessable_entity
end
end
def edit; end

# PATCH/PUT /funds/1
def update
if @fund.update(fund_params)
redirect_to @fund, notice: "Fund was successfully updated."
redirect_to @fund, notice: 'Fund was successfully updated.'
else
render :edit, status: :unprocessable_entity
end
end

# DELETE /funds/1
def destroy
@fund.destroy
redirect_to funds_url, notice: "Fund was successfully destroyed."
end
def destroy; end

private
# Use callbacks to share common setup or constraints between actions.
Expand Down
17 changes: 0 additions & 17 deletions app/views/funds/_form.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/funds/_fund.html.erb

This file was deleted.

32 changes: 32 additions & 0 deletions app/views/funds/_fund_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%= form_with(model: fund) do |form| %>
<% if fund.errors.any? %>
<div style="color: red">
<h2><%= pluralize(fund.errors.count, "error") %> prohibited this fund from being saved:</h2>

<ul>
<% fund.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.submit %>
</div>
<% end %>

<%= bootstrap_form_with model: @fund, local: true do |f| %>
<div class="row">
<div class="info-form-left col">
<%= f.text_field :name, autocomplete: 'off' %>
<%= f.text_field :subdomain, autocomplete: 'off' %>
<%= f.text_field :full_name, autocomplete: 'off' %>
<%= f.text_field :site_domain, autocomplete: 'off' %>
<%= f.text_field :phone,
autocomplete: 'off',
pattern: "[0-9]{10}|[0-9]{3}\.[0-9]{3}\.[0-9]{4}|[0-9]{3}[-][0-9]{3}[-][0-9]{4}" %>
</div>

<%= f.submit label, class: 'btn btn-primary btn-lg' %>
<% end %>
10 changes: 6 additions & 4 deletions app/views/funds/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<h1>Editing fund</h1>
<h1>
<%= t 'funds.edit.title' %>
</h1>

<%= render "form", fund: @fund %>

<br>
<%= render 'funds/fund_form',
fund: @fund,
label: t('funds.form.save_changes') %>

<div>
<%= link_to "Show this fund", @fund %> |
Expand Down
39 changes: 28 additions & 11 deletions app/views/funds/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
<p style="color: green"><%= notice %></p>
<h1><%= t 'funds.index.title' %></h1>

<h1>Funds</h1>
<div class="fund-list">
<table class="table border-side table-hover top-spacer" id="funds_table">
<thead>
<tr class="funds-table-header">
<th><!-- spacer --></th>
<th><%= t 'activerecord.attributes.fund.name' %></th>
<th><%= t 'activerecord.attributes.fund.subdomain' %></th>
<th><%= t 'activerecord.attributes.fund.domain' %></th>
<th><%= t 'activerecord.attributes.fund.full_name' %></th>
<th><%= t 'activerecord.attributes.fund.site_domain' %></th>
<th><%= t 'activerecord.attributes.fund.phone' %></th>
</tr>
</thead>

<div id="funds">
<% @funds.each do |fund| %>
<%= render fund %>
<p>
<%= link_to "Show this fund", fund %>
</p>
<% end %>
<tbody>
<% @funds.each do |fund| %>
<tr class="funds-table-row">
<td><!-- spacer --></td>
<td><%= link_to fund.name, edit_fund_path(fund) %></td>
<td><%= fund.subdomain %></td>
<td><%= fund.domain %></td>
<td><%= fund.full_name %></td>
<td><%= fund.site_domain %></td>
<td><%= fund.phone %></td>
</tr>
<% end %>
</tbody>
</table>
</div>

<%= link_to "New fund", new_fund_path %>
9 changes: 0 additions & 9 deletions app/views/funds/new.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/funds/show.html.erb

This file was deleted.

0 comments on commit af9560b

Please sign in to comment.