I have looked at this gropu and this page http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M000506 ...but I am unable to figure this out. Here are my tables (short version) People id fname lname state_id States id name I have the _form.rhtml working in a basic sense: <label for="person_state_id">State</label>: <%= select("person", "state_id", State.find(:all).collect {|s| [s.name, s.id]} ) %> It works fine when I am creating a new record. I select the state I want and the ID goes into the state_id field. The problem is when I go to edit the page it defaults to "Alabama," the first record. I need it to select the correct state ID. I have played with it a lot and basically I need it to print this: selected="selected" on the correct state. Suggestions? thanks --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-Sep-27 18:00 UTC
Re: need to print "selected=selected" when editing a form
On 9/27/07, Aaron Reimann <aaron.reimann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have looked at this gropu and this page > http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M000506 > > ...but I am unable to figure this out. > > Here are my tables (short version) > People > id > fname > lname > state_id > States > id > name > > I have the _form.rhtml working in a basic sense: > <label for="person_state_id">State</label>: <%= select("person", > "state_id", State.find(:all).collect {|s| [s.name, s.id]} ) %> > > It works fine when I am creating a new record. I select the state I > want and the ID goes into the state_id field. The problem is when I > go to edit the page it defaults to "Alabama," the first record. I > need it to select the correct state ID. I have played with it a lot > and basically I need it to print this: selected="selected" on the > correct state.Your controller needs to load the current row into an instance variable called @person. The selected state will be taken from @person.state_id Show us your controller code. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Aaron Reimann
2007-Sep-27 18:21 UTC
Re: need to print "selected=selected" when editing a form
def edit @person = Person.find(params[:id]) @interests = Interest.find(:all) @ministries = Ministry.find(:all) @phones = Phone.find(:all) @states = State.find(:all) end def update @person = Person.find(params[:id]) @person.interests = Interest.find(@params[:interest_ids]) if @params[:interest_ids] @person.ministries = Ministry.find(@params[:ministry_ids]) if @params[:ministry_ids] if @person.update_attributes(params[:person]) flash[:notice] = ''Person was successfully updated.'' redirect_to :action => ''show'', :id => @person else render :action => ''edit'' end end thanks On Sep 27, 2:00 pm, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9/27/07, Aaron Reimann <aaron.reim...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I have looked at this gropu and this page > >http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelp... > > > ...but I am unable to figure this out. > > > Here are my tables (short version) > > People > > id > > fname > > lname > > state_id > > States > > id > > name > > > I have the _form.rhtml working in a basic sense: > > <label for="person_state_id">State</label>: <%= select("person", > > "state_id", State.find(:all).collect {|s| [s.name, s.id]} ) %> > > > It works fine when I am creating a new record. I select the state I > > want and the ID goes into the state_id field. The problem is when I > > go to edit the page it defaults to "Alabama," the first record. I > > need it to select the correct state ID. I have played with it a lot > > and basically I need it to print this: selected="selected" on the > > correct state. > > Your controller needs to load the current row into an instance > variable called @person. The selected state will be taken from > @person.state_id > > Show us your controller code.--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
raghukumar
2007-Sep-28 05:25 UTC
Re: need to print "selected=selected" when editing a form
if you :selected option to select helper it will work, some thing like this, <label for="person_state_id">State</label>: <%= select("person", "state_id", State.find(:all).collect {|s| [s.name, s.id]}, {:selected =>@person.state_id} ) %> On Sep 27, 9:48 pm, Aaron Reimann <aaron.reim...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have looked at this gropu and this pagehttp://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelp... > > ...but I am unable to figure this out. > > Here are my tables (short version) > People > id > fname > lname > state_id > States > id > name > > I have the _form.rhtml working in a basic sense: > <label for="person_state_id">State</label>: <%= select("person", > "state_id", State.find(:all).collect {|s| [s.name, s.id]} ) %> > > It works fine when I am creating a new record. I select the state I > want and the ID goes into the state_id field. The problem is when I > go to edit the page it defaults to "Alabama," the first record. I > need it to select the correct state ID. I have played with it a lot > and basically I need it to print this: selected="selected" on the > correct state. > > Suggestions? > > thanks--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Aaron Reimann
2007-Oct-01 14:28 UTC
Re: need to print "selected=selected" when editing a form
I get the same problem. by default it has "alamaba" showing up and nothing is "selected=selected" in the html code. hmmmm.... On Sep 28, 1:25 am, raghukumar <raghukumar.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> if you :selected option to select helper it will work, some thing like > this, > > <label for="person_state_id">State</label>: <%= select("person", > "state_id", State.find(:all).collect {|s| [s.name, s.id]}, {:selected > =>@person.state_id} ) %> > > On Sep 27, 9:48 pm, Aaron Reimann <aaron.reim...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have looked at this gropu and this pagehttp://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelp... > > > ...but I am unable to figure this out. > > > Here are my tables (short version) > > People > > id > > fname > > lname > > state_id > > States > > id > > name > > > I have the _form.rhtml working in a basic sense: > > <label for="person_state_id">State</label>: <%= select("person", > > "state_id", State.find(:all).collect {|s| [s.name, s.id]} ) %> > > > It works fine when I am creating a new record. I select the state I > > want and the ID goes into the state_id field. The problem is when I > > go to edit the page it defaults to "Alabama," the first record. I > > need it to select the correct state ID. I have played with it a lot > > and basically I need it to print this: selected="selected" on the > > correct state. > > > Suggestions? > > > thanks--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
raghukumar
2007-Oct-02 12:59 UTC
Re: need to print "selected=selected" when editing a form
hey Aaron, <label for="person_state_id">State</label>: <%= select("person", "state_id", State.find(:all).collect {|s| [s.name, s.id]}, {:selected =>@person.state_id} ) %> even after trying above code, are you facing same problem? why because, according to rails document if you pass :selected options surely it should work. the 4th argument to select.. <%= select("person", "state_id", State.find(:all).collect {|s| [s.name, s.id]}, {:selected =>@person.state_id} ) %> On Oct 1, 7:28 pm, Aaron Reimann <aaron.reim...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I get the same problem. by default it has "alamaba" showing up and > nothing is "selected=selected" in the html code. > > hmmmm.... > > On Sep 28, 1:25 am, raghukumar <raghukumar.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > if you :selected option to select helper it will work, some thing like > > this, > > > <label for="person_state_id">State</label>: <%= select("person", > > "state_id", State.find(:all).collect {|s| [s.name, s.id]}, {:selected > > =>@person.state_id} ) %> > > > On Sep 27, 9:48 pm, Aaron Reimann <aaron.reim...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have looked at this gropu and this pagehttp://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelp... > > > > ...but I am unable to figure this out. > > > > Here are my tables (short version) > > > People > > > id > > > fname > > > lname > > > state_id > > > States > > > id > > > name > > > > I have the _form.rhtml working in a basic sense: > > > <label for="person_state_id">State</label>: <%= select("person", > > > "state_id", State.find(:all).collect {|s| [s.name, s.id]} ) %> > > > > It works fine when I am creating a new record. I select the state I > > > want and the ID goes into the state_id field. The problem is when I > > > go to edit the page it defaults to "Alabama," the first record. I > > > need it to select the correct state ID. I have played with it a lot > > > and basically I need it to print this: selected="selected" on the > > > correct state. > > > > Suggestions? > > > > thanks--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Aaron Reimann
2007-Oct-08 14:23 UTC
Re: need to print "selected=selected" when editing a form
I get this: compile error script/../config/../app/views/people/_form.rhtml:94: syntax error, unexpected kEND, expecting '')'' --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Oct-08 20:08 UTC
Re: need to print "selected=selected" when editing a form
On Oct 8, 2007, at 10:23 AM, Aaron Reimann wrote:> I get this: compile error > script/../config/../app/views/people/_form.rhtml:94: syntax error, > unexpected kEND, expecting '')''You are missing a '')'' somewhere above the line with the ''end'' (i.e., line 94) and the interpreter knows that ''end'' isn''t valid at that point so that''s where it complains. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org