hi all ,
can any body guide me, i have to fill the dropdown box with the name
of the states of the country at run time which is dependent on the
name of the country you selected.
is their any helper exists for this.
thanks
sachin
hi all ,
can any body guide me, i have to fill the dropdown box with the name
of the states of the country at run time which is dependent on the
name of the country you selected.
is their any helper exists for this.
thanks
sachin
Hi Sachin,
Something like this:
in your controller
@states = State.find_by_country(params[:country])
then in your view
<%= form.collection_select :state_id, @states, :id, :state %>
This example is based on form_for, so if you are using form_tag,
you’ll need the additional parameter at the beginning
<%= collection_select :person, :state_id, @states, :id, :state %>
Something like that anyway.
Peace,
Phillip
Oy. I just realized that I didn’t read the message closely enough.
I see now that you are needing to do one of two things:
I, personally, would go with #2. There is the argument that your app
should degrade gracefully if the user doesn’t have JavaScript
enabled, but I ignore that since my whole app depends on JavaScript
and I doubt that very many people actually have it disabled these
days. But that’s an architectural decision that I’ve made. Not
everyone would be comfortable with it.
I can provide an example of #2 if you like.
Sorry for the seeming incompetence on my part. I’ll try to read more
closely in the future.
Peace,
Phillip
Begin forwarded message:
please forward me the example if it is possible for you thanks
one more thing in your code what i realize is that i must have state
table in my database, which contains the name of the states for the
respective country or it is rails helper kind of thing
please confirm
thanks
Use render :inline to populate the values for the state dropdown.
Summarize:
[email protected] wrote:
one more thing in your code what i realize is that i must have state
table in my database, which contains the name of the states for the
respective country or it is rails helper kind of thingplease confirm
thanks
Probably, you can use observe_field to post the ajax request when
country is getting changed
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs