# Add method parameter for form helper

**URL:** <https://www.ruby-forum.com/t/add-method-parameter-for-form-helper/97920>\
**Category:** Rails\
**Created:** [July 11, 2006, 1:43pm UTC](https://www.ruby-forum.com/t/add-method-parameter-for-form-helper/97920 "2006-07-11T13:43:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnaud\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/46a35a/32.png) [@Arnaud\_G](https://www.ruby-forum.com/u/Arnaud_G)\
**Post date:** [July 11, 2006, 1:43pm UTC](https://www.ruby-forum.com/t/add-method-parameter-for-form-helper/97920/1 "2006-07-11T13:43:27Z")

</div>

Hello,

Most of the form helpers are build using Object / Method without the  
possibility of using a method parameter (as I know …)

```
text_field(object_name, method, options = {})

```

how do you solve this problem ?

-\> (I did my own helper and generate the html … well I think there is  
a better way;-)  
-\> do I have to overide text\_field(object\_name, method, parameters {},  
options = {})

thanks  
arnaud

---

<div class="post-metadata">

**Author:** ![Arnaud\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/46a35a/32.png) [@Arnaud\_G](https://www.ruby-forum.com/u/Arnaud_G)\
**Post date:** [July 11, 2006, 2:08pm UTC](https://www.ruby-forum.com/t/add-method-parameter-for-form-helper/97920/2 "2006-07-11T14:08:05Z")

</div>

hi bill,  
Instead of a simple object method (without parameter) Person.firstName  
=\> text\_field(“Person”,“firstName”)  
I have something like Person.display(“firstName”) so the text\_field  
cannot be populate by the simple call Person.display … I need to give  
the parameter for display method …

Thanks for help,

arnaud

Bill W. a écrit :

---

<div class="post-metadata">

**Author:** ![Arnaud\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/46a35a/32.png) [@Arnaud\_G](https://www.ruby-forum.com/u/Arnaud_G)\
**Post date:** [July 11, 2006, 1:49pm UTC](https://www.ruby-forum.com/t/add-method-parameter-for-form-helper/97920/3 "2006-07-11T13:49:45Z")

</div>

Hi Arnaud,

Arnaud G. wrote:

> Most of the form helpers are build using Object / Method without the  
> possibility of using a method parameter (as I know …)
> 
> text\_field(object\_name, method, options = {})
> 
> how do you solve this problem ?

Could you say more about exactly what you’re trying to accomplish? I’m  
not  
sure what you mean by ‘method parameter’.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![Arnaud\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/46a35a/32.png) [@Arnaud\_G](https://www.ruby-forum.com/u/Arnaud_G)\
**Post date:** [July 11, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/add-method-parameter-for-form-helper/97920/4 "2006-07-11T18:12:19Z")

</div>

sorry bill but Person.firstname was just an example, I know that rails  
will automatically call Person.firstname and populate the textfield …I  
just write it to illustrate the mechanism that rails “just” call a  
method on the object… The problem is how you do if you want to  
populate with Object.method(param1) ?

Bill W. a écrit :

---

<div class="post-metadata">

**Author:** ![Arnaud\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/46a35a/32.png) [@Arnaud\_G](https://www.ruby-forum.com/u/Arnaud_G)\
**Post date:** [July 11, 2006, 2:44pm UTC](https://www.ruby-forum.com/t/add-method-parameter-for-form-helper/97920/5 "2006-07-11T14:44:37Z")

</div>

Hi Arnaud,

Arnaud G. wrote:

> Instead of a simple object method (without parameter) Person.firstName =\>  
> text\_field(“Person”,“firstName”)  
> I have something like Person.display(“firstName”) so the text\_field cannot  
> be populate by the simple call Person.display … I need to give the  
> parameter for display method …

text\_field is already bound to the ‘firstName’ attribute of the ‘Person’  
object in your example. You don’t need a display method to have your  
view  
display the value. You need to pass the ‘Person’ object to the view  
from  
the controller and text\_field will automatically display the value of  
the  
attribute. To illustrate, let’s assume you’ve already entered a record  
for  
‘Dave’ and now want to edit it.

In your edit.rhtml view, you’ll have statements like…

\<%= text\_field ‘Person’, ‘firstName’ %\>  
\<%= text\_field ‘Person’, ‘lastName’ %\>  
\<%= text\_field ‘Person’, ‘address’ %\>

In your controller, your edit action / method will look like…

def edit  
@Person = Actor.find(:first, :conditions [“firstName = ?”, ‘Dave’] )  
end

The controller code above assumes ‘Actor’ is the class name of the  
Person  
object.

One more note… you might want to take a look at the wiki or pick up a  
book or two to get a handle on Rails naming conventions. Understanding  
those conventions is a necessary first-step towards success with Rails.

hth,  
Bill
