Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign form attributes #8

Open
vad4msiu opened this issue Oct 13, 2014 · 10 comments
Open

Assign form attributes #8

vad4msiu opened this issue Oct 13, 2014 · 10 comments

Comments

@vad4msiu
Copy link

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?

@m-Peter
Copy link

m-Peter commented Nov 27, 2014

You're correct. The functionality you describe is the desired. I'll work on it.

@kaspth
Copy link

kaspth commented Nov 27, 2014

Actually I think how it works currently is the desired way. Library users are expected to use strong parameters.

cc @guilleiguaran

@andrey-skat
Copy link

@kaspth Why to use strong parameters if you are using form objects? We already list all allowed attributes in attributes of ActiveForm. Why we need duplicate these attributes in controller?

@vad4msiu
Copy link
Author

vad4msiu commented Dec 1, 2014

👍 I agree with the comment above

@kaspth
Copy link

kaspth commented Dec 1, 2014

I don't mind the duplication concern expressed here as I'm not DRY religious (not saying you are).

To me it feels odd that a form specifies its accepted attributes. Rails moved away from attr_accessible and this kind of introduces it again. That's part of a controller and why Strong Parameters was added.

On the other hand, specifying attributes does bring a certain clarity to the form.

What do you think, @m-Peter?

@andrey-skat
Copy link

attr_accessible and attributes in form object it's not the same thing.

I concerned about duplication not because DRY, but because keeping in sync many attributes between form and controller bored.

@m-Peter
Copy link

m-Peter commented Dec 1, 2014

I share the same opinion with @andrey-skat . I had a hard time trying to setup the nested hierarchy nature that strong_parameters require.

@m-Peter
Copy link

m-Peter commented Dec 4, 2014

There is a WIP in this commit: 8e847e7 . Let me know your thoughts about it.

@kaspth
Copy link

kaspth commented Dec 6, 2014

@andrey-skat I know they functionally aren't the same, but effectively they are for what we're talking about.

@m-Peter I've left some comments for you on that linked commit.

@m-Peter
Copy link

m-Peter commented Dec 6, 2014

@kaspth Thanks for your help! I've applied them and will update the commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants