Default value for country_select

101 views
Skip to first unread message

Ratnavel Sundaramurthi

unread,
Dec 6, 2007, 7:35:44 AM12/6/07
to rubyonra...@googlegroups.com
Using Country_select how to have default valur set to United States.

I have a select drop down in my Ui to display the Country names.

But i need United tates to be selected as default value.

I use country_select to populate the country names.

This is how i use <%= f.country_select :country, :selected=>'United
States' %>
i also tried
<%= f.country_select :country, :priority_countries=>'United States' %>

Do help me out to fix this..

Thanks in advance
Ratnavel.
--
Posted via http://www.ruby-forum.com/.

ebrad

unread,
Dec 6, 2007, 9:54:04 AM12/6/07
to Ruby on Rails: Talk
helps? http://snippets.dzone.com/tag/country_select

On Dec 6, 7:35 am, Ratnavel Sundaramurthi <rails-mailing-l...@andreas-

Ratnavel Sundaramurthi

unread,
Dec 6, 2007, 11:16:53 PM12/6/07
to rubyonra...@googlegroups.com
ebrad wrote:
> helps? http://snippets.dzone.com/tag/country_select
>
> On Dec 6, 7:35 am, Ratnavel Sundaramurthi <rails-mailing-l...@andreas-

Thanks for the reply ebrad

I Used as this

<%= form.country_select :billing_country, ["United States"] %>, its
working..

BUT,

This is adding a option extra in the top as United states, the same
happened to me when i used the other two options which i mentioned
earlier..

Is it possible to show the United States in the list selected as
default.

Ryan Bigg

unread,
Dec 6, 2007, 11:26:52 PM12/6/07
to rubyonra...@googlegroups.com
what brad suggested is the way to do it. This will select United States as the first country.

Ratnavel Sundaramurthi

unread,
Dec 6, 2007, 11:35:57 PM12/6/07
to rubyonra...@googlegroups.com

Thank u Ryan I implemented in the same way as u both suggested...

Liang zan Wong

unread,
Mar 21, 2008, 3:28:43 AM3/21/08
to rubyonra...@googlegroups.com
Ryan Bigg wrote:
> what brad suggested is the way to do it. This will select United States
> as
> the first country.
>
> On Dec 7, 2007 2:46 PM, Ratnavel Sundaramurthi <
> rails-mai...@andreas-s.net> wrote:
>
>> <%= form.country_select :billing_country, ["United States"] %>, its
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>> >
>>
>
>
> --
> Ryan Bigg

Hi,

If you want to use the 'selected' option instead of putting it as a
priority country, you could try this

<%= form.country_select :billing_country, [], {:selected => "United
States"} %>

Liang Zan

Feras Sh

unread,
May 27, 2008, 4:29:58 PM5/27/08
to rubyonra...@googlegroups.com

> Hi,
>
> If you want to use the 'selected' option instead of putting it as a
> priority country, you could try this
>
> <%= form.country_select :billing_country, [], {:selected => "United
> States"} %>
>
> Liang Zan

I tried this, but still showing the first country ( afganestan ). do
you have any idea about that ?
thank you

Sijo Kg

unread,
May 30, 2008, 12:34:05 AM5/30/08
to rubyonra...@googlegroups.com
Hi
Please tell me how you solved it.Becasuse I have a similar
problem..I am using two country_select as

<%= country_select(:contact_address1, :country) %>
<%= country_select(:contact_address2, :country) %>

The above is working..But the default is Afganistan..How can I change
this default to "UnitedStates"

Thanks in advance
Sijo

Aston J.

unread,
Feb 22, 2012, 4:41:01 PM2/22/12
to rubyonra...@googlegroups.com
I know this is a few years olf but just in case it helps anyone, you can
use :prompt => true to add a 'please select' default option

Anu Sebastian

unread,
Mar 13, 2014, 2:26:56 AM3/13/14
to rubyonra...@googlegroups.com
how to add defult value to the country_select gem.. pls help me

tamouse pontiki

unread,
Mar 15, 2014, 2:06:36 AM3/15/14
to rubyonra...@googlegroups.com
On Thu, Mar 13, 2014 at 1:26 AM, Anu Sebastian <li...@ruby-forum.com> wrote:
> how to add defult value to the country_select gem.. pls help me
>

I don't know for sure, but I think you can pass in an option:
`:selected => code` where code is the country code.

Anu Sebastian

unread,
Apr 2, 2014, 11:52:05 PM4/2/14
to rubyonra...@googlegroups.com
tamouse m. wrote in post #1139937:
not working......

tamouse pontiki

unread,
Apr 3, 2014, 6:35:24 AM4/3/14
to rubyonra...@googlegroups.com
On Wed, Apr 2, 2014 at 10:52 PM, Anu Sebastian <li...@ruby-forum.com> wrote:
> tamouse m. wrote in post #1139937:
>> On Thu, Mar 13, 2014 at 1:26 AM, Anu Sebastian <li...@ruby-forum.com>
>> wrote:
>>> how to add defult value to the country_select gem.. pls help me
>>>
>>
>> I don't know for sure, but I think you can pass in an option:
>> `:selected => code` where code is the country code.
>
> not working......

Show your code.

This is on the README page:

Supplying additional html options:

country_select("user", "country", { priority_countries: ["GB",
"FR"] }, { selected: "GB", class: 'form-control' })

Anu Sebastian

unread,
May 23, 2014, 1:08:24 AM5/23/14
to rubyonra...@googlegroups.com
tamouse m. wrote in post #1141848:
here s my code
<%=country_select("profile", "country", { priority_countries: ["GB",
"FR"] }, { selected: "GB")%>
after excecuting the code. default country selected as afganistan.. no
change..
pls help me to find a solution

Anu Sebastian

unread,
May 23, 2014, 1:08:52 AM5/23/14
to rubyonra...@googlegroups.com
here s my code
<%=country_select("profile", "country", { priority_countries: ["GB",
"FR"] }, { selected: "GB")%>
after excecuting the code. default country selected as afganistan.. no
change..
pls help me to find a solution

Reply all
Reply to author
Forward
0 new messages