Skip to content

Instantly share code, notes, and snippets.

@aseroff
Last active March 28, 2023 20:52
Show Gist options
  • Save aseroff/752472ef302edddb4b16fb71e4bc1f7d to your computer and use it in GitHub Desktop.
Save aseroff/752472ef302edddb4b16fb71e4bc1f7d to your computer and use it in GitHub Desktop.
Creating a selectbox for a form using ancestry SECRET OPTION #5

Options 1-4 seen here

Option 5: Directly writing to the Ancestry string field

  • In the form:
    <%= f.select :ancestry, [['- New Primary Category -', '/']] + Category.all.map{ |category| [category.name, "#{category.ancestry}#{category.id}/"] } %>

And that's literally it. This syntax is for the :materialized_path2 format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment