diff --git a/app/helpers/clients_helper.rb b/app/helpers/clients_helper.rb index 01829b1..fc4c84b 100644 --- a/app/helpers/clients_helper.rb +++ b/app/helpers/clients_helper.rb @@ -2,4 +2,8 @@ module ClientsHelper def client_form_fields [:company_name, :firstname, :lastname, :streetname, :zipcode, :city, :country, :email, :phone] end + + def client_view_fields + [:company_name, :firstname, :lastname, :streetname, :zipcode, :city, :country, :email, :phone] + end end diff --git a/app/views/clients/_client.html.erb b/app/views/clients/_client.html.erb index 4133422..3e6a7c5 100644 --- a/app/views/clients/_client.html.erb +++ b/app/views/clients/_client.html.erb @@ -1,47 +1,14 @@ -
-

- Company name: - <%= client.company_name %> -

- -

- Firstname: - <%= client.firstname %> -

- -

- Lastname: - <%= client.lastname %> -

- -

- Streetname: - <%= client.streetname %> -

- -

- Zipcode: - <%= client.zipcode %> -

- -

- City: - <%= client.city %> -

- -

- Country: - <%= client.country %> -

- -

- Email: - <%= client.email %> -

- -

- Phone: - <%= client.phone %> -

- -
+<% client_view_fields.each do |attrib| %> + + <% value = client.send(attrib) %> + <% if attrib == :company_name %> + <%= link_to value, client_path(client) %> + <% elsif attrib == :email %> + <%= mail_to value %> + <% elsif attrib == :phone %> + <%= link_to value, "tel:#{value.strip.gsub(/\s+/, '')}" %> + <% else %> + <%= value.is_a?(Date) ? l(value) : value %> + <% end %> + +<% end %> \ No newline at end of file diff --git a/app/views/clients/index.html.erb b/app/views/clients/index.html.erb index e651f4d..6c70bd7 100644 --- a/app/views/clients/index.html.erb +++ b/app/views/clients/index.html.erb @@ -5,12 +5,22 @@

Clients

- <% @clients.each do |client| %> - <%= render client %> -

- <%= link_to "Show this client", client %> -

- <% end %> + + + + <% client_view_fields.each do |attrib| %> + + <% end %> + + + + <% @clients.each do |client| %> + + <%= render client %> + + <% end %> + +
<%= attrib.to_s.humanize %>
<%= link_to "New client", new_client_path %> diff --git a/app/views/clients/show.html.erb b/app/views/clients/show.html.erb index 20794cf..102395b 100644 --- a/app/views/clients/show.html.erb +++ b/app/views/clients/show.html.erb @@ -1,6 +1,25 @@

<%= notice %>

-<%= render @client %> +<% content_for :title, "Client: #{@client.company_name}" %> + +

Client: <%= @client.company_name %>

+ +
+ + + + <% client_view_fields.each do |attrib| %> + + <% end %> + + + + + <%= render @client %> + + +
<%= attrib.to_s.humanize %>
+
<%= link_to "Edit this client", edit_client_path(@client) %> |