Skip to content

Commit

Permalink
Creating the Customers Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
QISUN000 committed Feb 27, 2025
1 parent 2ad64de commit 945b1d0
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CustomersController < ApplicationController
def index
@customers = Customer.all
end

def alphabetized
@customers = Customer.order(:full_name)
end

def missing_email
@customers = Customer.where(email_address: [nil, ""])
end
end
2 changes: 2 additions & 0 deletions app/helpers/customers_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CustomersHelper
end
29 changes: 29 additions & 0 deletions app/views/customers/_customer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="card mb-4">
<div class="card-content">
<div class="media">
<div class="media-left">
<figure class="image is-96x96">
<% if customer.image.attached? %>
<%= image_tag customer.image, class: "is-rounded" %>
<% else %>
<%= image_tag "default_profile.png", class: "is-rounded" %>
<% end %>
</figure>
</div>
<div class="media-content">
<p class="title is-4"><%= customer.full_name %></p>
<p class="subtitle is-6">
<% if customer.email_address.present? %>
<%= customer.email_address %>
<% else %>
<span class="has-text-danger">No email provided</span>
<% end %>
</p>
</div>
</div>
<div class="content">
<p><strong>Phone:</strong> <%= customer.phone_number %></p>
<p><%= customer.notes %></p>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions app/views/customers/alphabetized.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Customers#alphabetized</h1>
<p>Find me in app/views/customers/alphabetized.html.erb</p>
2 changes: 2 additions & 0 deletions app/views/customers/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Customers#index</h1>
<p>Find me in app/views/customers/index.html.erb</p>
2 changes: 2 additions & 0 deletions app/views/customers/missing_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Customers#missing_email</h1>
<p>Find me in app/views/customers/missing_email.html.erb</p>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Rails.application.routes.draw do
get "customers/index"
get "customers/alphabetized"
get "customers/missing_email"
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
Expand Down
18 changes: 18 additions & 0 deletions test/controllers/customers_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "test_helper"

class CustomersControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get customers_index_url
assert_response :success
end

test "should get alphabetized" do
get customers_alphabetized_url
assert_response :success
end

test "should get missing_email" do
get customers_missing_email_url
assert_response :success
end
end

0 comments on commit 945b1d0

Please sign in to comment.