diff options
| -rw-r--r-- | app/controllers/clients_controller.rb | 20 | ||||
| -rw-r--r-- | app/controllers/visits_controller.rb | 24 | ||||
| -rw-r--r-- | app/views/home/index.html.haml | 2 | ||||
| -rw-r--r-- | app/views/visits/new.html.haml (renamed from app/views/clients/log_visit_form.html.haml) | 2 | ||||
| -rw-r--r-- | config/routes.rb | 3 |
5 files changed, 27 insertions, 24 deletions
diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index be95b8d..0e4399c 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -23,20 +23,6 @@ class ClientsController < ApplicationController render json: json end - def log_visit_form - @visit = Visit.new - end - - def log_visit - @visit = Visit.new(visit_params) - - if @visit.save - redirect_to root_path, notice: 'Visit Logged!' - else - render :log_visit_form, status: :unprocessable_entity - end - end - private def client_params @@ -45,10 +31,4 @@ class ClientsController < ApplicationController :last_name, ) end - - def visit_params - params.require(:visit).permit( - :client_id, - ) - end end diff --git a/app/controllers/visits_controller.rb b/app/controllers/visits_controller.rb new file mode 100644 index 0000000..672bede --- /dev/null +++ b/app/controllers/visits_controller.rb @@ -0,0 +1,24 @@ +class VisitsController < ApplicationController + + def new + @visit = Visit.new + end + + def create + @visit = Visit.new(visit_params) + + if @visit.save + redirect_to root_path, notice: 'Visit Logged!' + else + render :new, status: :unprocessable_entity + end + end + + private + + def visit_params + params.require(:visit).permit( + :client_id, + ) + end +end diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 542cbfd..66730e3 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -3,7 +3,7 @@ %b Client Operations .grid - = button_to "Log a Visit", log_visit_form_clients_path, method: :get + = button_to "Log a Visit", new_visit_path, method: :get = button_to "Register a New Client", new_client_path, method: :get - if Current.user.admin? diff --git a/app/views/clients/log_visit_form.html.haml b/app/views/visits/new.html.haml index fbd5b07..9223ccd 100644 --- a/app/views/clients/log_visit_form.html.haml +++ b/app/views/visits/new.html.haml @@ -2,7 +2,7 @@ %header %b Log a New Visit - = simple_form_for @visit, url: log_visit_clients_path do |f| + = simple_form_for @visit do |f| = f.input :client_id, input_html: { hidden: true } -# TODO: Add client information here once chosen diff --git a/config/routes.rb b/config/routes.rb index 5871d48..58b6d43 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,10 +15,9 @@ Rails.application.routes.draw do root "home#index" resources :clients, only: [ :new, :create ] do - get 'log_visit_form', on: :collection - post 'log_visit', on: :collection get 'find', on: :collection end + resources :visits, only: [ :new, :create ] resources :users, only: [ :new, :create ] end |
