Hello Friends, I am a newbie in ROR. Can you plz tell me how to populate the combobox with data from db?If you could give both the view and controller part it would be helpful.I am using a Mysql database -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
on Controller ---------------------------- def index @categories = Category.find(:all) end on View ---------------------------------------- <%= select("post", "category_id", @categories.collect {|p| [ p.name, p.id ] }, {:include_blank => ''None''})%> On Tue, Feb 16, 2010 at 5:08 PM, Veena Jose <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello Friends, > I am a newbie in ROR. > Can you plz tell me how to populate the combobox with data from db?If > you could give both the view and controller part it would be helpful.I > am using a Mysql database > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
or you can use this in your view: <%= collection_select(:video, :category_id, Category.all, :id, :name) %> Category.all can be called in your controller and passed to the form tag as instance variable... something like @categories = Category.all then <%= collection_select(:video, :category_id, @categories, :id, :name) %> On Feb 16, 11:50 am, Bala <bala.mutha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> on Controller > ---------------------------- > > def index > @categories = Category.find(:all) > end > > on View > ---------------------------------------- > <%= select("post", "category_id", @categories.collect {|p| [ p.name, p.id ] > > }, {:include_blank => ''None''})%> > On Tue, Feb 16, 2010 at 5:08 PM, Veena Jose <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Hello Friends, > > I am a newbie in ROR. > > Can you plz tell me how to populate the combobox with data from db?If > > you could give both the view and controller part it would be helpful.I > > am using a Mysql database > > -- > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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?hl=en.
Bala wrote:> on Controller > ---------------------------- > > def index > @categories = Category.find(:all) > end > > on View > ---------------------------------------- > <%= select("post", "category_id", @categories.collect {|p| [ p.name, > p.id ] > }, {:include_blank => ''None''})%>Thank you so much.....Ur code exactly worked for me.... -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
welcome On Wed, Feb 17, 2010 at 9:43 AM, Veena Jose <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Bala wrote: > > on Controller > > ---------------------------- > > > > def index > > @categories = Category.find(:all) > > end > > > > on View > > ---------------------------------------- > > <%= select("post", "category_id", @categories.collect {|p| [ p.name, > > p.id ] > > }, {:include_blank => ''None''})%> > > > > Thank you so much.....Ur code exactly worked for me.... > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.