refactor view to helper method
This commit is contained in:
@@ -6,4 +6,15 @@ module SubprojectsHelper
|
|||||||
def subproject_view_fields
|
def subproject_view_fields
|
||||||
[:subproject_name, :project, :client, :owner, :builder, :subproject_address]
|
[:subproject_name, :project, :client, :owner, :builder, :subproject_address]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def subproject_form_input(form, attrib, subproject)
|
||||||
|
case attrib
|
||||||
|
when :project
|
||||||
|
form.collection_select :project_id, Project.all, :id, ->(project) { project.name }, prompt: "Select Project"
|
||||||
|
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}"
|
||||||
|
else
|
||||||
|
form.text_field attrib, value: subproject.send(attrib)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,17 +12,10 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% subproject_form_fields.each do |attrib| %>
|
<% subproject_form_fields.each do |attrib| %>
|
||||||
<div>
|
<div>
|
||||||
<%= form.label attrib, style: "display: block" %>
|
<%= form.label attrib, style: "display: block" %>
|
||||||
<% case attrib %>
|
<%= subproject_form_input(form, attrib, subproject) %>
|
||||||
<% when :project %>
|
</div>
|
||||||
<%= form.collection_select :project_id, Project.all, :id, -> (project) { "#{project.name}" }, prompt: "Select Project" %>
|
|
||||||
<% when :client, :owner, :builder %>
|
|
||||||
<%= form.collection_select "#{attrib}_id", Client.all, :id, -> (client) { "#{client.company_name} (#{client.lastname}, #{client.firstname})" }, prompt: "Select #{attrib.capitalize}" %>
|
|
||||||
<% else %>
|
|
||||||
<%= form.text_field attrib, value: subproject.send(attrib) %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user