bug fixing using cursor
This commit is contained in:
@@ -49,8 +49,15 @@ class ClientsController < ApplicationController
|
|||||||
|
|
||||||
# DELETE /clients/1 or /clients/1.json
|
# DELETE /clients/1 or /clients/1.json
|
||||||
def destroy
|
def destroy
|
||||||
@client.destroy!
|
if @client.referenced_count > 0
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to clients_path, alert: "Client is referenced by subprojects and cannot be deleted." }
|
||||||
|
format.json { render json: { error: "Client has references" }, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
@client.destroy!
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to clients_path, status: :see_other, notice: "Client was successfully destroyed." }
|
format.html { redirect_to clients_path, status: :see_other, notice: "Client was successfully destroyed." }
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ module SubprojectsHelper
|
|||||||
def subproject_form_input(form, attrib, subproject)
|
def subproject_form_input(form, attrib, subproject)
|
||||||
case attrib
|
case attrib
|
||||||
when :project
|
when :project
|
||||||
form.collection_select :project_id, Project.all, :id, ->(project) { project.name }, prompt: "Select Project"
|
form.collection_select :project_id, Project.all, :id, :name, prompt: "Select Project"
|
||||||
when :client, :owner, :builder
|
when :client, :owner, :builder
|
||||||
form.collection_select "#{attrib}_id", Client.all, :id, ->(client) { "#{client.company_name} (#{client.lastname}, #{client.firstname})" }, prompt: "Select #{attrib.to_s.capitalize}"
|
form.collection_select "#{attrib}_id", Client.all, :id, :display_name, prompt: "Select #{attrib.to_s.capitalize}"
|
||||||
else
|
else
|
||||||
form.text_field attrib, value: subproject.send(attrib)
|
form.text_field attrib, value: subproject.send(attrib)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,4 +13,8 @@ class Client < ApplicationRecord
|
|||||||
def editable?
|
def editable?
|
||||||
referenced_count <= 1
|
referenced_count <= 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def display_name
|
||||||
|
"#{company_name} (#{lastname}, #{firstname})"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
class Project < ApplicationRecord
|
class Project < ApplicationRecord
|
||||||
has_many :subprojects, inverse_of: :project
|
has_many :subprojects, inverse_of: :project, dependent: :destroy
|
||||||
accepts_nested_attributes_for :subprojects, allow_destroy: true, reject_if: :all_blank
|
accepts_nested_attributes_for :subprojects, allow_destroy: true, reject_if: :all_blank
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
|||||||
@@ -56,8 +56,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<%= form.submit %>
|
<%= form.submit %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user