Add method parameter for form helper

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

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 :

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

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 :

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs