mirror of
https://github.com/fspc/bike-database.git
synced 2025-04-04 10:03:22 -04:00
lk | redirect to new form when successfully creating a client - allow for easier bulk creation
This commit is contained in:
parent
d49f6030ed
commit
a0b0fd4714
@ -16,7 +16,7 @@ class ClientsController < ApplicationController
|
|||||||
def create
|
def create
|
||||||
@client = Client.new(client_params)
|
@client = Client.new(client_params)
|
||||||
if @client.save
|
if @client.save
|
||||||
redirect_to edit_client_url(@client), notice: 'Client was successfully created.'
|
redirect_to new_client_path, notice: 'Client was successfully created.'
|
||||||
else
|
else
|
||||||
render action: 'new'
|
render action: 'new'
|
||||||
end
|
end
|
||||||
|
@ -8,4 +8,4 @@
|
|||||||
= render 'fields', f: f
|
= render 'fields', f: f
|
||||||
.row
|
.row
|
||||||
.actions.col-sm-offset-2
|
.actions.col-sm-offset-2
|
||||||
= f.submit class: "btn btn-default"
|
= f.submit "Save Changes", class: "btn btn-default"
|
11
app/views/clients/_new_form.html.haml
Normal file
11
app/views/clients/_new_form.html.haml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
= form_for @client, html: {class: 'form-horizontal'} do |f|
|
||||||
|
- if @client.errors.any?
|
||||||
|
#error_explanation
|
||||||
|
%h2= pluralize(@client.errors.count, "error") + " prohibited this client from being saved:"
|
||||||
|
%ul
|
||||||
|
- @client.errors.full_messages.each do |msg|
|
||||||
|
%li= msg
|
||||||
|
= render 'fields', f: f
|
||||||
|
.row
|
||||||
|
.actions.col-sm-offset-2
|
||||||
|
= f.submit "Save And Add Another", class: "btn btn-default"
|
@ -1,5 +1,5 @@
|
|||||||
.container
|
.container
|
||||||
%h1 Edit client
|
%h1 Edit client
|
||||||
= render 'receipt_button' if @client.bike_id
|
= render 'receipt_button' if @client.bike_id
|
||||||
= render 'form'
|
= render 'edit_form'
|
||||||
= link_to 'Back', clients_path
|
= link_to 'Back', clients_path
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
.container
|
.container
|
||||||
%h1 New Client
|
%h1 New Client
|
||||||
= render 'form'
|
= render 'new_form'
|
||||||
= link_to 'Back', clients_path
|
= link_to 'Back', clients_path
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
%br
|
%br
|
||||||
%h2 Freecyclery
|
%h2 Freecyclery
|
||||||
%br
|
%br
|
||||||
|
= link_to "Add Freecyclery Clients", new_client_path
|
||||||
|
%br
|
||||||
= link_to "Freecyclery Clients", clients_path
|
= link_to "Freecyclery Clients", clients_path
|
||||||
%br
|
%br
|
||||||
= link_to "Freecyclery Agencies", agencies_path
|
= link_to "Freecyclery Agencies", agencies_path
|
||||||
|
@ -8,6 +8,14 @@ describe ClientsController do
|
|||||||
sign_in user
|
sign_in user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "POST #create" do
|
||||||
|
it "redirects to new_client_path on success" do
|
||||||
|
client_attributes = attributes_for :client
|
||||||
|
request = post :create, client: client_attributes
|
||||||
|
expect(request).to redirect_to action: :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#print_select" do
|
describe "#print_select" do
|
||||||
it "only assigns clients with a bike and an agency" do
|
it "only assigns clients with a bike and an agency" do
|
||||||
client_with_bike_and_agency = create :client, bike: create(:bike), agency: create(:agency)
|
client_with_bike_and_agency = create :client, bike: create(:bike), agency: create(:agency)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user