hi all,
i am new to rails and not able to figure how to get a drop-down
selection list in a view.
i have 3 models (tables): country, state & city.
country has many states
state has many cities
now i want to create 3 drop down lists, 1 for each. selecting a
country should make states available in that country only, and same
for the state and cities.
i am trying to create the ''country'' list with this:
<%= collection_select(:state, :countries_id,
@countries, :id, :cou_name, {:prompt => "select country"}) %>
def select
@countries = Country.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @countries }
end
end
although the box is shown, but nothing comes up in it.
i am trying to do this inside a view for ''state''. do i need to
do it
inside a separate controller/view??
plz help!!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
You need either javascript code, or an observer. This is not trivial. Start simply, one step at a time. Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 04/02/2009, at 4:41 PM, Sahil Dave <sahil.dave19-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > hi all, > > i am new to rails and not able to figure how to get a drop-down > selection list in a view. > i have 3 models (tables): country, state & city. > country has many states > state has many cities > > now i want to create 3 drop down lists, 1 for each. selecting a > country should make states available in that country only, and same > for the state and cities. > > i am trying to create the ''country'' list with this: > <%= collection_select(:state, :countries_id, > @countries, :id, :cou_name, {:prompt => "select country"}) %> > > def select > @countries = Country.find(:all) > > respond_to do |format| > format.html # index.html.erb > format.xml { render :xml => @countries } > end > end > > although the box is shown, but nothing comes up in it. > i am trying to do this inside a view for ''state''. do i need to do it > inside a separate controller/view?? > > plz help!! > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You seem to be complicating things. I think this is what you need
<%= collection_select(:state, :country_id, Country.find
(:all), :id, :cou_name, {:prompt => "select country"}) %>
you do not need the "select" method in the controller for this. Unless
of course you WANT an Ajax call to be made for some reason, in which
case, you need to explain more on what exactly you need.
On Feb 4, 2:49 pm, Julian Leviston
<jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org>
wrote:> You need either javascript code, or an observer. This is not trivial.
> Start simply, one step at a time.
>
> Blog:http://random8.zenunit.com/
> Learn rails:http://sensei.zenunit.com/
>
> On 04/02/2009, at 4:41 PM, Sahil Dave
<sahil.dav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
> > hi all,
>
> > i am new to rails and not able to figure how to get a drop-down
> > selection list in a view.
> > i have 3 models (tables): country, state & city.
> > country has many states
> > state has many cities
>
> > now i want to create 3 drop down lists, 1 for each. selecting a
> > country should make states available in that country only, and same
> > for the state and cities.
>
> > i am trying to create the ''country'' list with this:
> > <%= collection_select(:state, :countries_id,
> > @countries, :id, :cou_name, {:prompt => "select
country"}) %>
>
> > def select
> > @countries = Country.find(:all)
>
> > respond_to do |format|
> > format.html # index.html.erb
> > format.xml { render :xml => @countries }
> > end
> > end
>
> > although the box is shown, but nothing comes up in it.
> > i am trying to do this inside a view for ''state''. do
i need to do it
> > inside a separate controller/view??
>
> > plz help!!
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---