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 Arnaud, Arnaud Garcia 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
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 Walton a ?crit :> Hi Arnaud, > > Arnaud Garcia 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi Arnaud, Arnaud Garcia 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
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 Walton a ?crit :> Hi Arnaud, > > Arnaud Garcia 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Maybe Matching Threads
- Overwrite form helper methods and call old ones in new ones?
- Login form question
- ActionView::Helpers::FormHelper instance methods should take an object reference rather than an object_name.
- Turn element hidden by default (ajax question)
- ActionView::TemplateError (can't convert ActiveRecord::Error into String)