All Questions


Diego Enjamio

Page Builder

Hi, im playing around page builder. Modeling Page, PageComponent and Component. I figure out need json column for save custom data for component. But now struggling how to achieve different forms for each component.

Can you point me in the right direction? Thanks!

  • Nick Haskins replied

    Hey Diego!

    Yep so what I would do is create a migration and set that column as JSONB, it's native to PostgreSQL and is great for storing key-value data.

    add_column :customers, :social_links, :jsonb, default:'{}'

    With that you'd be able to pull data from customer.social_links['twitter']

    Setting this up in a form you would use fields_for. I use SimpleForm but the concept is the same for vanilla Rails.

    Gist here:

    Does this help?

  • E
    Diego Enjamio replied

    Yes! Thats is, I dont know about fields_for with jsonb, nice trick for my pocket. Now, any easy way for render the correct custom fields for each component?

    Really appreciate

  • Nick Haskins replied

    To render the fields for each component you would just put them into a normal form for the component. The fields_for would go into that same form. If you know what the key names will be, you can just do something like in the gist above.