I want to create a select tag from a table. Looking through the API don''t believe I could find it. Table has an id and label. Labels would be displayed, id would be saved. 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 -~----------~----~----~----~------~----~------~--~---
a trivial example: <%= select("node","node_type_id", NodeType.find(:all,:order => "name").collect{|node| [node.name, node.id]}) %> Dark Ambient escribió:> > I want to create a select tag from a table. Looking through the API > don''t believe I could find it. > Table has an id and label. Labels would be displayed, id would be saved. > > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thanks I wound up going with this : <%@states = State.find(:all, :order => "name") collection_select(:state, :name, @states, :id, :name) %> Just wondering , this is in the view , I probably should move this to the model, i.e. def list_states ....... end Or helper or controller, I realize I have all options but since I''m a rails newb open for suggestions. Stuart On 8/28/06, Matias Surdi <matiassurdi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > a trivial example: > > <%= select("node","node_type_id", NodeType.find(:all,:order > => "name").collect{|node| [node.name, node.id]}) %> > > > > Dark Ambient escribió: > > > > > I want to create a select tag from a table. Looking through the API > > don''t believe I could find it. > > Table has an id and label. Labels would be displayed, id would be saved. > > > > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Now I''m having a problem. In my controller I have this: def state @states = State.find(:all, :order => "name") end When I try to access the @states in the view I get a nil error: <%collection_select(:state, :name, @states, :id, :name) %> What am I missing ? TIA Stuart On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks I wound up going with this : > > <%> @states = State.find(:all, :order => "name") > collection_select(:state, :name, @states, :id, :name) > %> > > Just wondering , this is in the view , I probably should move this to > the model, i.e. > def list_states > ....... > end > > Or helper or controller, I realize I have all options but since I''m a > rails newb open for suggestions. > > Stuart > > On 8/28/06, Matias Surdi <matiassurdi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > a trivial example: > > > > <%= select("node","node_type_id", NodeType.find(:all,:order > > => "name").collect{|node| [node.name, node.id]}) %> > > > > > > > > Dark Ambient escribió: > > > > > > > > I want to create a select tag from a table. Looking through the API > > > don''t believe I could find it. > > > Table has an id and label. Labels would be displayed, id would be saved. > > > > > > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I think you need to do that in the action before you use it. I mean, it can''t be in ''state'' cos that is called when you go to: http://localhost:3000/controller/state If you want it to be accessed in other places, you will need to put it in those functions, places like ''new'', ''create'', ''update'' etc.. Hope this helps, Cheers Mohit. Dark Ambient wrote:> Now I''m having a problem. In my controller I have this: > def state > @states = State.find(:all, :order => "name") > end > > When I try to access the @states in the view I get a nil error: > <%> collection_select(:state, :name, @states, :id, :name) > %> > > What am I missing ? > > TIA > Stuart > > > On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Thanks I wound up going with this : >> >> <%>> @states = State.find(:all, :order => "name") >> collection_select(:state, :name, @states, :id, :name) >> %> >> >> Just wondering , this is in the view , I probably should move this to >> the model, i.e. >> def list_states >> ....... >> end >> >> Or helper or controller, I realize I have all options but since I''m a >> rails newb open for suggestions. >> >> Stuart >> >> On 8/28/06, Matias Surdi <matiassurdi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> a trivial example: >>> >>> <%= select("node","node_type_id", NodeType.find(:all,:order >>> => "name").collect{|node| [node.name, node.id]}) %> >>> >>> >>> >>> Dark Ambient escribió: >>> >>> >>>> I want to create a select tag from a table. Looking through the API >>>> don''t believe I could find it. >>>> Table has an id and label. Labels would be displayed, id would be saved. >>>> >>>> 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Now I''m having a problem. In my controller I have this: > def state > @states = State.find(:all, :order => "name") > end > When I try to access the @states in the view I get a nil error: > <%> collection_select(:state, :name, @states, :id, :name) > %> >Most likely @states doesn''t exist when the view is rendered. In the standard scaffold, you must setup @states in the edit, new and [for the validation errors] in the error part of the update actions. Regards, Thomas --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The API doc is a bit confusing on collection_select: collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) So object I''d think would be State and method I could call list_state (in the controller) or maybe I''m better off putting in the model though that hasn''t worked either yet. Stuart On 8/28/06, T wenrich <twenrich-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Now I''m having a problem. In my controller I have this: > > def state > > @states = State.find(:all, :order => "name") > > end > > When I try to access the @states in the view I get a nil error: > > <%> > collection_select(:state, :name, @states, :id, :name) > > %> > > > > Most likely @states doesn''t exist when the view is rendered. In the standard > scaffold, you must setup @states in the edit, new and [for the validation > errors] in the error part of the update actions. > > Regards, > > Thomas > > > > >--~--~---------~--~----~------------~-------~--~----~ 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:> Now I''m having a problem. In my controller I have this: > def state > @states = State.find(:all, :order => "name") > end > > When I try to access the @states in the view I get a nil error: > <%> collection_select(:state, :name, @states, :id, :name) > %> > > What am I missing ? > > TIA > Stuarttry <%collection_select(:state, :state_id, @states, :id, :name) %> Brian -- 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 -~----------~----~----~----~------~----~------~--~---
I had yesterday a similar problem; because I thought I might need exactly this list in other tables, too I did this to application_helper.rb: module ApplicationHelper def country_select(parent, fk = :country_id, opt = {:include_blank => true}) countries = Country.find :all, :order => :name collection_select(parent, fk, countries, :id, :name, opt) end end <p><label for="breeder_country_id">Country</label><br/> <%= country_select :breeder %></p> But note that I''m also new to ruby & rails - I''m sure there are much better approaches. e.g. this misses some handling of the default opt parameter. Thomas --~--~---------~--~----~------------~-------~--~----~ 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 not following the new, edit or error idea. Stuart On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The API doc is a bit confusing on collection_select: > collection_select(object, method, collection, value_method, > text_method, options = {}, html_options = {}) > So object I''d think would be State and method I could call list_state > (in the controller) > or maybe I''m better off putting in the model though that hasn''t worked > either yet. > > Stuart > > On 8/28/06, T wenrich <twenrich-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Now I''m having a problem. In my controller I have this: > > > def state > > > @states = State.find(:all, :order => "name") > > > end > > > When I try to access the @states in the view I get a nil error: > > > <%> > > collection_select(:state, :name, @states, :id, :name) > > > %> > > > > > > > Most likely @states doesn''t exist when the view is rendered. In the standard > > scaffold, you must setup @states in the edit, new and [for the validation > > errors] in the error part of the update actions. > > > > Regards, > > > > Thomas > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Incorrect. Lets say you have a model "address", that contains a column "state_id": @states = State.find(:all) Then in your view: collection_select ("address", "state_id", :id, :name) When the form is posted, the id of the selected "state" will be @address.state_id (assuming @address = Address.new(params[:address])) Maybe this is more along the lines of what you are looking to do? -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Dark Ambient Sent: Monday, August 28, 2006 12:02 PM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: Question: Help with select tag The API doc is a bit confusing on collection_select: collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) So object I''d think would be State and method I could call list_state (in the controller) or maybe I''m better off putting in the model though that hasn''t worked either yet. Stuart On 8/28/06, T wenrich <twenrich-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Now I''m having a problem. In my controller I have this: > > def state > > @states = State.find(:all, :order => "name") > > end > > When I try to access the @states in the view I get a nil error: > > <%> > collection_select(:state, :name, @states, :id, :name) > > %> > > > > Most likely @states doesn''t exist when the view is rendered. In thestandard> scaffold, you must setup @states in the edit, new and [for the validation > errors] in the error part of the update actions. > > Regards, > > Thomas > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks but no , still getting a nil object. What I don''t get up the CRUD reference (above) is that all I"m trying to do is create the list / array and access it from the form. It''s not going to be updated , merely a form element to get values from . Stuart On 8/28/06, Brian Deweese <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Stuart Fellowes wrote: > > Now I''m having a problem. In my controller I have this: > > def state > > @states = State.find(:all, :order => "name") > > end > > > > When I try to access the @states in the view I get a nil error: > > <%> > collection_select(:state, :name, @states, :id, :name) > > %> > > > > What am I missing ? > > > > TIA > > Stuart > > try > > <%> collection_select(:state, :state_id, @states, :id, :name) > %> > > Brian > > -- > 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 8/28/06, Michael Scappa <mscappa-yVCTJHzobNA9DSYl/7C2QwC/G2K4zDHf@public.gmane.org> wrote:> Lets say you have a model "address", that contains a column "state_id": > > @states = State.find(:all) > > Then in your view: > > collection_select ("address", "state_id", :id, :name) > > When the form is posted, the id of the selected "state" will be > @address.state_id (assuming @address = Address.new(params[:address])) > > Maybe this is more along the lines of what you are looking to do?Maybe, but I think this is similar to what I''m doing already. I have a model State (table states) column names are id and state so this in the view works: <%@states = State.find(:all, :order => "name") collection_select(:state, :name, @states, :id, :name) %> Yet, moving the find to a model , controller or helper is not working. Am I missing something in everyones responses ? 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 -~----------~----~----~----~------~----~------~--~---
I found a solution and not sure if it''s the right one but ....... In the helper for the associated controller: def liststates @states = State.find(:all, :order => "name") end Then in the view: collection_select(:state, liststates, @states, :id, :name) Stuart On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 8/28/06, Michael Scappa <mscappa-yVCTJHzobNA9DSYl/7C2QwC/G2K4zDHf@public.gmane.org> wrote: > > Lets say you have a model "address", that contains a column "state_id": > > > > @states = State.find(:all) > > > > Then in your view: > > > > collection_select ("address", "state_id", :id, :name) > > > > When the form is posted, the id of the selected "state" will be > > @address.state_id (assuming @address = Address.new(params[:address])) > > > > Maybe this is more along the lines of what you are looking to do? > > Maybe, but I think this is similar to what I''m doing already. > I have a model State (table states) > column names are id and state > > so this in the view works: > <%> @states = State.find(:all, :order => "name") > collection_select(:state, :name, @states, :id, :name) > %> > > Yet, moving the find to a model , controller or helper is not working. > > Am I missing something in everyones responses ? > 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, if you put it into an action called ''state'' in the controller, the variable @states is visible only in that action (state) So, if you access the URL: http://localhost:3000/controller/state then @states is visible. If you want it to be available in the action ''new'', you want to load the variable @states before you render the view for it. that means it needs to be a part of the ''new'' action like this: def new @states = State.find_all @clinic = Clinic.new end This way, the @states variable is visible in the view for new. Does this make sense? As to where it should be moved, "code" within views belongs in helpers. Cheers Mohit. Dark Ambient wrote:> I''m not following the new, edit or error idea. > Stuart > > On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> The API doc is a bit confusing on collection_select: >> collection_select(object, method, collection, value_method, >> text_method, options = {}, html_options = {}) >> So object I''d think would be State and method I could call list_state >> (in the controller) >> or maybe I''m better off putting in the model though that hasn''t worked >> either yet. >> >> Stuart >> >> On 8/28/06, T wenrich <twenrich-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> >>> On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> Now I''m having a problem. In my controller I have this: >>>> def state >>>> @states = State.find(:all, :order => "name") >>>> end >>>> When I try to access the @states in the view I get a nil error: >>>> <%>>>> collection_select(:state, :name, @states, :id, :name) >>>> %> >>>> >>>> >>> Most likely @states doesn''t exist when the view is rendered. In the standard >>> scaffold, you must setup @states in the edit, new and [for the validation >>> errors] in the error part of the update actions. >>> >>> Regards, >>> >>> Thomas >>> >>> >>> > > >>> >>> > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Mohit, and that is where it is now . Stuart On 8/28/06, Mohit Sindhwani <mo_mail-RxrYI66vbj0AvxtiuMwx3w@public.gmane.org> wrote:> > Stuart, if you put it into an action called ''state'' in the controller, > the variable @states is visible only in that action (state) > So, if you access the URL: > http://localhost:3000/controller/state then @states is visible. > > If you want it to be available in the action ''new'', you want to load the > variable @states before you render the view for it. that means it needs > to be a part of the ''new'' action like this: > def new > @states = State.find_all > @clinic = Clinic.new > end > > This way, the @states variable is visible in the view for new. Does > this make sense? > > As to where it should be moved, "code" within views belongs in helpers. > > Cheers > Mohit. > > > Dark Ambient wrote: > > I''m not following the new, edit or error idea. > > Stuart > > > > On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >> The API doc is a bit confusing on collection_select: > >> collection_select(object, method, collection, value_method, > >> text_method, options = {}, html_options = {}) > >> So object I''d think would be State and method I could call list_state > >> (in the controller) > >> or maybe I''m better off putting in the model though that hasn''t worked > >> either yet. > >> > >> Stuart > >> > >> On 8/28/06, T wenrich <twenrich-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > >>> > >>> On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>> > >>>> Now I''m having a problem. In my controller I have this: > >>>> def state > >>>> @states = State.find(:all, :order => "name") > >>>> end > >>>> When I try to access the @states in the view I get a nil error: > >>>> <%> >>>> collection_select(:state, :name, @states, :id, :name) > >>>> %> > >>>> > >>>> > >>> Most likely @states doesn''t exist when the view is rendered. In the standard > >>> scaffold, you must setup @states in the edit, new and [for the validation > >>> errors] in the error part of the update actions. > >>> > >>> Regards, > >>> > >>> Thomas > >>> > >>> > >>> > > > >>> > >>> > > > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That is correct - the only "code" in a view should be stored in a helper function. If you need it more than 1 controller, consider adding it to the application helper. Cheers Mohit. Dark Ambient wrote:> I found a solution and not sure if it''s the right one but ....... > In the helper for the associated controller: > > def liststates > @states = State.find(:all, :order => "name") > end > > Then in the view: > > collection_select(:state, liststates, @states, :id, :name) > > Stuart > > On 8/28/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On 8/28/06, Michael Scappa <mscappa-yVCTJHzobNA9DSYl/7C2QwC/G2K4zDHf@public.gmane.org> wrote: >> >>> Lets say you have a model "address", that contains a column "state_id": >>> >>> @states = State.find(:all) >>> >>> Then in your view: >>> >>> collection_select ("address", "state_id", :id, :name) >>> >>> When the form is posted, the id of the selected "state" will be >>> @address.state_id (assuming @address = Address.new(params[:address])) >>> >>> Maybe this is more along the lines of what you are looking to do? >>> >> Maybe, but I think this is similar to what I''m doing already. >> I have a model State (table states) >> column names are id and state >> >> so this in the view works: >> <%>> @states = State.find(:all, :order => "name") >> collection_select(:state, :name, @states, :id, :name) >> %> >> >> Yet, moving the find to a model , controller or helper is not working. >> >> Am I missing something in everyones responses ? >> 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 -~----------~----~----~----~------~----~------~--~---