Skip to content

Assign form attributes #8

Open
Open
@vad4msiu

Description

@vad4msiu

I have form:

class Forms::Publishers::CreateForm < ActiveForm::Base
  attributes :name
  validates :name, presence: true
end

Then in a controller I submit params:

form = Forms::Publishers::CreateForm.new(publisher)
form.submit(params)

But if params contain not name key (example: foo) I have error: NoMethodError: undefined method foo=' for #Forms::Publishers::CreateForm:0x007f85805f70a0. It force my to use params.slice(...)orstrong_parameters` gem. Why not just ignore attributes which don't defined? I thought form should receive any params but assign only defined?

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