ruby on rails - How do I get the country_select gem and simple_form to work from scratch? -


I just want a simple country dropdown, which has been given priority for my purposes (i.e. the states located in the country do).

In fact, I only want 1 or 2 countries.

I am using Simple_Form and their documents say that to get access to:

/ Code>

I need to include it in my jammfile:

  gem 'country_select'  

but I'm confused I do not have to run a migration to store the country selection on my selection. Post model - the model for my _form.html.erb Research

When I simply do:

  ;% = f.input: country, like: country, collection: ["Australia", "Brazil "," New Zealand "]%>  

I did not find any country method on the post error me this my post.rb : To add to attr_accessor: country

, if my memory works correctly to me, due to the powerful parameter, now I should not do in Rail 4, okay? < / P>

This works, but now archive: prompts The sh does not work. I still see a long list of countries.

Keep in mind that I post your . No migration has been run to modify the RB model. I do not know what to add to the column. Will I add the country, state, city to my post model or do I have a new model called country Make it

What is all this information about countries being loaded in the gem (country code, city, state etc.) through a YAML file in the gem?

I have no clue and the documentation is surprisingly sparse.

So my questions are:

  1. How do I get this simple_form to work on the collection.
  2. How to
  3. Do I have to supply this other data somewhere in a table?
  4. How do I do the Country & amp; My posted record

thanks

Solution 1:

The document for simple_form is for use with country_select 1.x. To use Simple_Form as a document, restrict the version of country_select in your gemfile:

  Mani 'country_select', '~ & gt; 1.0 ' 

and then bundle update country_select to downgrade.

Solution 2:

If you want to use country_select 2.x instead, you will work with country code, not country names. Your form assistant will look a bit simpler than the simple_form docs:

  & lt;% = f.input: country_code, as :: country, priority: ['BR']% & gt; Either   for  

solution

needs to add a column to your postal model that the user has selected in your database is . Data type will be a string / behavior that can generate migration in such a way:

  Rail Migration Generates Rails: AddCountryCodeToPost country_code: string  

country_select only countries Knows about

Not a city or state.

If you want to supply users or states to the States, you will be able to store them in the text fields and store them in the form of wires (for your model for them) Columns can add up as above), or choose your own / auto-complete system creation. There is a state_select gem, but you will need to integrate it manually with the country- select javascript or a pipeline form. I am not aware of any gem providing data source for city names from state / country, but there can be some very good there.

Note

For more information, see the differences between country 1.x and country_select 2.x, see.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -