YaleSTC/shifts

View on GitHub
app/views/users/_user_profile.html.erb

Summary

Maintainability
Test Coverage
<%= fields_for @user_profile do |f| %>
  <p>
    <% if @user_profile_entries != [] %>
      <% @user_profile_entries.each do |entry| %>
        <% args = entry.prepare_form_helpers %>
        <p>
          <%= label "user_profile_entries[#{entry.id}]", "#{entry.field_name}" %><br/>

          <% if ["text_field", "select", "text_area"].include? entry.display_type %>
            <%= send(entry.display_type, *args) %>
          <% elsif entry.display_type == "picture_link" %>
            <%= send("text_field", *args) %>

          <% elsif entry.display_type == "upload_pic" %>
            <%= render partial: "user_profiles/user_profile_pic", object: UserProfilePics.new %>

          <% elsif ["radio_button"].include? entry.display_type %>
            <% args.each do |options| %>
              <%= send(entry.display_type, *options) %>
              <%= label "user_profile_entries[#{entry.id}]", "#{options.third}" %>
            <% end %>
          <% elsif ["check_box"].include? entry.display_type %>
            <% args.each do |options| %>
              <%= send(entry.display_type, *options) %>
              <%= label "user_profile_entries[#{entry.id}]", "#{options.second}" %>
          <% end %>
        <% end %>

      <% end %>
    <% else %>
      There don't appear to be any profile fields for this department. Want to <%= link_to "add one", new_user_profile_field_path %>?
    <% end %>
  </p>

<% end %>