I''m having problems pulling up an edit page with 3 text fields. The text fields look like such - <%= text_field(:cantitle, :title_opt, "index" => 1)%> <%= text_field(:cantitle, :title_opt, "index" => 2)%> <%= text_field(:cantitle, :title_opt,"index" => 3)%> In my controller - @cantitles = Cantitle.find(:all, :conditions => ["candidate_id = ?", @candidate_id]) I thought perhaps I could use the instance variable @cantitles in the text_field elements , but not enough arguments. Not sure how to go about this. Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/27/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m having problems pulling up an edit page with 3 text fields. > The text fields look like such - > <%= text_field(:cantitle, :title_opt, "index" => 1)%> > <%= text_field(:cantitle, :title_opt, "index" => 2)%> > <%= text_field(:cantitle, :title_opt,"index" => 3)%> > > In my controller - @cantitles = Cantitle.find(:all, :conditions => > ["candidate_id = ?", @candidate_id]) > > I thought perhaps I could use the instance variable @cantitles in the > text_field elements , but not enough arguments. > Not sure how to go about this.Changed controller code to @cantitle = Cantitle.find(:all, :conditions => ["candidate_id = ?", @candidate_id]) undefined method `title_opt'' for #<Array:0x485e760> Stuart --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
bump Still haven''t figured out how to pull the values into the update form. Adding map @cantitle = Cantitle.find(:all, :conditions => ["candidate_id = ?", @candidate_id]).map {|x| x.title_opt} still throws an exception undefined method `title_opt'' for ["Channel manager", "Regional Sales manager", "Sales manager"]:Array I know title_opt is not undefined,I''ve gone over all the association thrice. I''m sure it has something to do with the way I''m pulling the array out of the database Stuart On 10/27/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 10/27/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m having problems pulling up an edit page with 3 text fields. > > The text fields look like such - > > <%= text_field(:cantitle, :title_opt, "index" => 1)%> > > <%= text_field(:cantitle, :title_opt, "index" => 2)%> > > <%= text_field(:cantitle, :title_opt,"index" => 3)%> > > > > In my controller - @cantitles = Cantitle.find(:all, :conditions => > > ["candidate_id = ?", @candidate_id]) > > > > I thought perhaps I could use the instance variable @cantitles in the > > text_field elements , but not enough arguments. > > Not sure how to go about this. > > > Changed controller code to @cantitle = Cantitle.find(:all, :conditions => > ["candidate_id = ?", @candidate_id]) > > undefined method `title_opt'' for #<Array:0x485e760> > > > Stuart > >-- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I''m going to start this message over again since I may not have explained it well the first time. I have multiple text_field(s) in my edit form. Each one is for the same model method, however each field has a unique index number . My problem is getting the records from the database into the text_fields. These are the fields: <%= text_field(:cantitle, :title_opt, "index" => 1)%> <%= text_field(:cantitle, :title_opt, "index" => 2)%> <%= text_field(:cantitle, :title_opt,"index" => 3)%> I can fill an array in the controller with @cantitle = Cantitle.find(:all, :conditions => ["candidate_id = ?", @candidate_id]).map {|x| x.title_opt} What I can''t figure out is how to loop it correctly so that each text field gets one of the values. Right now the find command throws an exception undefined method `title_opt'' for ["Channel manager", "Regional Sales manager", "Sales manager"]:Array Hope this is clear. TIA Stuart --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Stuart Fellowes wrote:> My problem is getting the records from the database into the > text_fields. > These are the fields: > <%= text_field(:cantitle, :title_opt, "index" => 1)%> > <%= text_field(:cantitle, :title_opt, "index" => 2)%> > <%= text_field(:cantitle, :title_opt,"index" => 3)%>I don''t believe this is possible with the text_field helper. text_field expects a symbol corresponding to a single model object to be passed as the first parameter, and you are passing it a symbol corresponding to an array object. text_field just isn''t built to handle editing of multiple records in the same view. (Someone please correct me if I''m off base here.) When I had to do something similar in one of my applications, I did it like this: <% @cheeses.each do |cheese| %> <%= text_field_tag("cheese[#{cheese.id}]", cheese.name) %> <% end %> I''m not sure if there''s a better way to do it, but this did work for me. Hope this gives you some ideas! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/27/06, Chris Gernon <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Stuart Fellowes wrote: > > My problem is getting the records from the database into the > > text_fields. > > These are the fields: > > <%= text_field(:cantitle, :title_opt, "index" => 1)%> > > <%= text_field(:cantitle, :title_opt, "index" => 2)%> > > <%= text_field(:cantitle, :title_opt,"index" => 3)%> > > I don''t believe this is possible with the text_field helper. text_field > expects a symbol corresponding to a single model object to be passed as > the first parameter, and you are passing it a symbol corresponding to an > array object. text_field just isn''t built to handle editing of multiple > records in the same view. (Someone please correct me if I''m off base > here.) > > When I had to do something similar in one of my applications, I did it > like this: > > <% @cheeses.each do |cheese| %> > <%= text_field_tag("cheese[#{cheese.id}]", cheese.name) %> > <% end %>Well for me it doesn''t work, but not sure if I should pursue it , since I believe it''s not sql safe. Stuart --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Stuart Fellowes wrote:> Well for me it doesn''t work, but not sure if I should pursue it , since > I > believe it''s not sql safe.um what SQL isn''t generated by view helpers; it''s generated by ActiveRecord calls from your controller. I''m not sure what you mean by "not sql safe" in this context. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
<%= text_field_tag("cheese[#{cheese.id}]", cheese.name) %> I guess I was thinking about the warning not to be the values directly into the conditions portion of a sql statement. Not sure if having them in the view is the same. Anyway I think I worked it out using <% @canlocations.each_with_index do |canlocation, indx| %> <%= text_field_tag "canlocation[#{indx}][city]", canlocation.city %><% end %> Which is similar to what you had suggested. Stuart On 10/28/06, Chris Gernon <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Stuart Fellowes wrote: > > Well for me it doesn''t work, but not sure if I should pursue it , since > > I > > believe it''s not sql safe. > > um > > what > > SQL isn''t generated by view helpers; it''s generated by ActiveRecord > calls from your controller. I''m not sure what you mean by "not sql safe" > in this context. > > -- > Posted via http://www.ruby-forum.com/. > > > >-- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Oct-28 12:07 UTC
Re: edit / update text_field
Hi -- On Fri, 27 Oct 2006, Chris Gernon wrote:> > Stuart Fellowes wrote: >> My problem is getting the records from the database into the >> text_fields. >> These are the fields: >> <%= text_field(:cantitle, :title_opt, "index" => 1)%> >> <%= text_field(:cantitle, :title_opt, "index" => 2)%> >> <%= text_field(:cantitle, :title_opt,"index" => 3)%> > > I don''t believe this is possible with the text_field helper. text_field > expects a symbol corresponding to a single model object to be passed as > the first parameter, and you are passing it a symbol corresponding to an > array object. text_field just isn''t built to handle editing of multiple > records in the same view. (Someone please correct me if I''m off base > here.) > > When I had to do something similar in one of my applications, I did it > like this: > > <% @cheeses.each do |cheese| %> > <%= text_field_tag("cheese[#{cheese.id}]", cheese.name) %> > <% end %> > > I''m not sure if there''s a better way to do it, but this did work for me. > Hope this gives you some ideas!There''s also: <% @cheeses.each do |@cheese| %> <%= text_field "cheese[]", "name" %> <% end %> which will give you a params hash like this: "cheese" => { "12" => { "name" => "brie" }, "33" => { "name" => "cheddar" } ... } where the integers are the ids of the records. David -- David A. Black | dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/28/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:> > > Hi -- > > On Fri, 27 Oct 2006, Chris Gernon wrote: > > > > > Stuart Fellowes wrote: > >> My problem is getting the records from the database into the > >> text_fields. > >> These are the fields: > >> <%= text_field(:cantitle, :title_opt, "index" => 1)%> > >> <%= text_field(:cantitle, :title_opt, "index" => 2)%> > >> <%= text_field(:cantitle, :title_opt,"index" => 3)%> > > > > I don''t believe this is possible with the text_field helper. text_field > > expects a symbol corresponding to a single model object to be passed as > > the first parameter, and you are passing it a symbol corresponding to an > > array object. text_field just isn''t built to handle editing of multiple > > records in the same view. (Someone please correct me if I''m off base > > here.) > > > > When I had to do something similar in one of my applications, I did it > > like this: > > > > <% @cheeses.each do |cheese| %> > > <%= text_field_tag("cheese[#{cheese.id}]", cheese.name) %> > > <% end %> > > > > I''m not sure if there''s a better way to do it, but this did work for me. > > Hope this gives you some ideas! > > There''s also: > > <% @cheeses.each do |@cheese| %> > <%= text_field "cheese[]", "name" %> > <% end %> > > which will give you a params hash like this: > > "cheese" => { "12" => { "name" => "brie" }, > "33" => { "name" => "cheddar" } > ... } > > where the integers are the ids of the records. > > > David > > -That works well also, Can I kick it up a notch, I want to do the same but with a select list Example: I have a collection_select that looks like this <%= collection_select(:canlocation, :state_id, @states, :id, :name) Similar to the text_field_tag above, there are multiple records in the users canlocations. In the controller I have this collection: @canlocation_options = Canlocation.find(:all,:conditions => ["candidate_id ?", @candidate_id]).map {|x| x.state_id} Now I''d like to map the canlocation_options to the collection_select. When the @states list is displayed it''s on the previously selected state. I thought perhaps this would work: <% @canlocation_options.each_with_index do |canlocation_options, indx| %> <%= collection_select(:canlocation, :state_id, @states, :id, :name, :selected => "canlocation_options[#{indx}][state_id]") canlocation_options.state_id %> <% end %> ndefined method `state_id'' for 12:Fixnum I''m open to suggestions. Stuart --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 10/28/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote: > > > > > > Hi -- > > > > On Fri, 27 Oct 2006, Chris Gernon wrote: > > > > > > > > Stuart Fellowes wrote: > > >> My problem is getting the records from the database into the > > >> text_fields. > > >> These are the fields: > > >> <%= text_field(:cantitle, :title_opt, "index" => 1)%> > > >> <%= text_field(:cantitle, :title_opt, "index" => 2)%> > > >> <%= text_field(:cantitle, :title_opt,"index" => 3)%> > > > > > > I don''t believe this is possible with the text_field helper. > > text_field > > > expects a symbol corresponding to a single model object to be passed > > as > > > the first parameter, and you are passing it a symbol corresponding to > > an > > > array object. text_field just isn''t built to handle editing of > > multiple > > > records in the same view. (Someone please correct me if I''m off base > > > here.) > > > > > > When I had to do something similar in one of my applications, I did it > > > > > like this: > > > > > > <% @cheeses.each do |cheese| %> > > > <%= text_field_tag("cheese[#{cheese.id}]", cheese.name) %> > > > <% end %> > > > > > > I''m not sure if there''s a better way to do it, but this did work for > > me. > > > Hope this gives you some ideas! > > > > There''s also: > > > > <% @cheeses.each do |@cheese| %> > > <%= text_field "cheese[]", "name" %> > > <% end %> > > > > which will give you a params hash like this: > > > > "cheese" => { "12" => { "name" => "brie" }, > > "33" => { "name" => "cheddar" } > > ... } > > > > where the integers are the ids of the records. > > > > > > David > > > > - > > That works well also, > Can I kick it up a notch, > I want to do the same but with a select list > > Example: > I have a collection_select that looks like this > <%= collection_select(:canlocation, :state_id, @states, :id, :name) > Similar to the text_field_tag above, there are multiple records in the > users canlocations. > > In the controller I have this collection: > @canlocation_options = Canlocation.find(:all,:conditions => ["candidate_id > = ?", @candidate_id]).map {|x| x.state_id} > > Now I''d like to map the canlocation_options to the collection_select. When > the @states list is displayed it''s on the previously selected state. > > I thought perhaps this would work: > > <% @canlocation_options.each_with_index do |canlocation_options, indx| %> > > <%= collection_select(:canlocation, :state_id, @states, :id, :name, > :selected => "canlocation_options[#{indx}][state_id]") > canlocation_options.state_id %> > <% end %> > > ndefined method `state_id'' for 12:Fixnum > > > I''m open to suggestions. > Stuart >I solved the collection_select by doing this: @canlocation_options = Canlocation.find(:all,:conditions => ["candidate_id ?", @candidate_id]).map {|x| x.state_id} Then in the form: <select name=canlocation[state_id]><%= options_from_collection_for_select @states, :id, :name, @canlocation_options[0] %> <select name=canlocation[state_id]><%= options_from_collection_for_select @states, :id, :name, @canlocation_options[1] %> <select name=canlocation[state_id]><%= options_from_collection_for_select @states, :id, :name, @canlocation_options[2] %> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---