Homepage

[DEPRECATED] Sharing Attributes Across Multiple Profiles

Last edit: Jan 31, 2024

Warning

This article series promote UserProfiles and Forms, which are deprecated. We decided to reduce the learning curve by promoting explicit implementation via Liuid, Pages and GraphQL, instead of a built-in features, which add magic into the mix and hence increase the learning curve and makes debugging harder. Please refer to our Get Started to read up-to date articles, including User Authentication

This guide will help you share attributes across multiple user profiles.
If your profiles happen to have the same Properties, you can extract them to a container profile which will group them and could be used in different profiles.

Requirements

To follow the steps in this tutorial, you should be familiar with users and user profiles. This guide builds on previous tutorials in the Users section.

Steps

Sharing attributes across multiple user profiles is a three-step process:

Step 1: Create profile template

Create a general employee template. You can define other profiles that will have fields from the employee profile and some more.

app/user_profile_types/employee.yml
name: employee
properties:
  - name: name
    type: string
  - name: email
    type: string
  - name: emergency_contact
    type: string

Step 2: Create profiles

app/user_profile_types/software_developer.yml
name: software_developer
properties:
  - name: programming_languages
    type: array
app/user_profile_types/project_manager.yml
name: project_manager
properties:
  - name: projects_managed
    type: array

Step 3: Use profiles

An example of using the software developer profile on a sign-up form:

app/forms/software_developer_signup.liquid
---
name: software_developer_signup
redirect_to: /software-developer/sign-in
resource: User
fields:
  profiles:
    validation: { presence: true }
    employee:
      validation: { presence: true }
      properties:
        validation: { presence: true }
        name: { validation: { presence: true } }
        email: { validation: { presence: true } }
        emergency_contact: { validation: { presence: true } }
    software_developer:
      validation: { presence: true }
      properties:
        validation: { presence: true }
        programming_languages:  { validation: { presence: true } }
---
[...]

An example of using the project manager profile on a sign-up form:

app/forms/project_manager_signup.liquid
---
name: project_manager_signup
redirect_to: /project-manager/sign-in
resource: User
fields:
  profiles:
    validation: { presence: true }
    employee:
      validation: { presence: true }
      properties:
        validation: { presence: true }
        name: { validation: { presence: true } }
        email: { validation: { presence: true } }
        emergency_contact: { validation: { presence: true } }
    project_manager:
      validation: { presence: true }
      properties:
        validation: { presence: true }
        projects:  { validation: { presence: true } }
---
[...]

Note

If you would like to create a profile on sign up without assigning any property, please make sure that params would include at minimum form[profiles_attributes][_attributes]. You can achieve it with hidden input and form or via default_payload json.


Note

To discover names that fields should have, explore the form variable by printing it on your page.

Next steps

Congratulations! You know how to share attributes across user profiles. You can learn more about Forms here:

Questions?

We are always happy to help with any questions you may have.

contact us