# Formatting form post to work with MyClass.new(params\[:my\_cla

**URL:** <https://www.ruby-forum.com/t/formatting-form-post-to-work-with-myclass-new-params-my-cla/112784>\
**Category:** Rails\
**Created:** [August 23, 2007, 7:13am UTC](https://www.ruby-forum.com/t/formatting-form-post-to-work-with-myclass-new-params-my-cla/112784 "2007-08-23T07:13:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 23, 2007, 7:13am UTC](https://www.ruby-forum.com/t/formatting-form-post-to-work-with-myclass-new-params-my-cla/112784/1 "2007-08-23T07:13:52Z")

</div>

So,

In my html page I have a simple (non rails generated) html for that  
posts to the server via an ajax call using prototype’s form.serialize.  
It used to post to an [asp.net](http://asp.net) page, but now I want it to post to my  
rails controller. This is what I have:

@my\_class = MyClass.new(params[:my\_class])

I don’t want to have to set each property of MyClass one-by-one, I  
want to do what the above code shows. I want to pass all the necessary  
values to the MyClass constructor.

How can I translate my html form values to do this?

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 23, 2007, 7:17am UTC](https://www.ruby-forum.com/t/formatting-form-post-to-work-with-myclass-new-params-my-cla/112784/2 "2007-08-23T07:17:52Z")

</div>

On 8/23/07, eggie5 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I don’t want to have to set each property of MyClass one-by-one, I  
> want to do what the above code shows. I want to pass all the necessary  
> values to the MyClass constructor.
> 
> How can I translate my html form values to do this?

For it do do this your form inputs need to be named

name=“mycalss[fieldname]”

Then it will work like you want. If you can’t have everything named  
like  
that, you’ll need to do it manually.

HTH  
Daniel

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 23, 2007, 7:38am UTC](https://www.ruby-forum.com/t/formatting-form-post-to-work-with-myclass-new-params-my-cla/112784/3 "2007-08-23T07:38:54Z")

</div>

Ahhh, that you for showing me the scheme. Where is this documented?

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 23, 2007, 7:46am UTC](https://www.ruby-forum.com/t/formatting-form-post-to-work-with-myclass-new-params-my-cla/112784/4 "2007-08-23T07:46:55Z")

</div>

On 8/23/07, eggie5 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > want to do what the above code shows. I want to pass all the necessary  
> > > that, you’ll need to do it manually.
> > 
> > HTH  
> > Daniel

It is documented indirectly here

> **[ActionView::Helpers::FormHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html)**
>
> Form helpers are designed to make working with resources much easier compared to using vanilla HTML.

-Daniel
