如何修改country-state-select?

时间:2016-09-08 20:04:54

标签: ruby-on-rails rubygems

我想在我的应用程序中定制rails gem上的这个ruby。类似于:拥有特定国家/地区的数据。当在上面的gem中选择该国家/地区时,我希望我在该应用中使用的国家/地区具有不同的数据。这是可能的,对于记录我不知道是否为特定国家/地区拥有不同的数据库。有关更多重点,请参阅下文。

使用gem country-state-select ...

if country == Russia then
  # the data from the country would be used..
  # should the data for this country be in database?
else
  # the flow of the gem still works for other countries

1 个答案:

答案 0 :(得分:0)

如果您希望访问者能够编辑/删除/添加该国家/地区的数据,那么您肯定需要拥有一个数据库。但是,否则您不必为每个国家/地区使用数据库列。您可以渲染部分内容,如

if country == Russia 
render 'russia'

elsif country == Germany
render 'germany'
...

除此之外,您还可以使用jQuery来完成此任务。

    $(document).on('change', '.country_select', function() {
     if ($(this).val('russia')) (
      $('.show_text_here_div').text('blablablal information about russia');
     )
     else if ($(this).val('Germany')) (
      $('.show_text_here_div').text('blablablal information about germany');
     )
    });