Skip to content

Improved ActiveRecord Association support #14

@bradgessler

Description

@bradgessler

I've had a few questions about this issue and realize there's no description, so here it is!

Imagine a form like this:

# How it should work 😎
Superform @project do |form|
  render form.field(:name).input
  render form.field(:category).select(Category.select(:id, :name)))
end

The category field would submit back to Rails as category, which wouldn't work properly. Instead, what Rails expects, is category_id.

Currently Superform call model.send field on an object. Instead it should inflect on ActiveModel and ActiveRecord classes to see if a field is an association. If it is an association, it can get the foreign key and emit category_id as the name of the field.

# How it works today 😬
Superform @project do |form|
  render form.field(:name).input
  render form.field(:category_id).select(Category.select(:id, :name)))
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions