rails_bootstrap_form 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 258bf9fab2788b0c8cb56a29936c65f5f2db39c4b34f8bf0b0c6cfc1cf9aec0e
4
- data.tar.gz: bfe585f59942a256f5f7ed95b393acb993499eddfe1f7f7ad67e97184afa0673
3
+ metadata.gz: 5874a38745d73c1b0bb05c751711cdc380be8684c71187069e07224e9d40333a
4
+ data.tar.gz: ffe2043c13700e6015d7741b51550c52642098c412f29b1921a7e98ed20ec9cf
5
5
  SHA512:
6
- metadata.gz: f0d869fb1a264159585ace5eab0a776641358205862bdf072b40c845e922a8e846a2119d32feee31b93dcb35fd9dd1c156669bd05a4260469a15367fdb146650
7
- data.tar.gz: a67cbe82b6aec6a4459715085eca05d692cb5f3ad5629972785e81c028163e2dbaaaf56d44f036be93f4f79008d924b78161259c13746742129970763676e1e3
6
+ metadata.gz: 657b116576955954f11ecd923cd61277613bd732d7b986effe3d5b908ed38531549413baa47436167fd7d675fb5aab709863cc53bfb19f99d4a39abb2148de63
7
+ data.tar.gz: '09d24eb35c72a56c834d0031ce85152e1a0241a1d4614dc69ebb5bc820b45780380d80132a9c882086b6524d8bb9fd5826d41c339f45bd87b335fcb0ceb97eeb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.4.1)
4
+ rails_bootstrap_form (0.4.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ class City < ApplicationRecord
6
+ DEFAULT_OPTIONS = {
7
+ "India" => ["Mumbai", "New Delhi", "Kolkata", "Chennai"],
8
+ "Ireland" => ["Dublin", "Galway", "Cork", "Belfast"],
9
+ "United States" => ["New York", "Los Angeles", "San Francisco", "Chicago"],
10
+ "United Kingdom" => ["London", "Edinburgh", "Manchester", "Bristol"],
11
+ "Spain" => ["Barcelona", "Madrid", "Seville", "Granada"],
12
+ "France" => ["Paris", "Nice", "Lyon", "Marseille"],
13
+ "Canada" => ["Toronto", "Montreal", "Vancouver", "Calgary"],
14
+ }.freeze
15
+
16
+ belongs_to :country
17
+ end
@@ -14,4 +14,5 @@ class Country < ApplicationRecord
14
14
  ].freeze
15
15
 
16
16
  has_many :addresses, dependent: :restrict_with_exception
17
+ has_many :cities, dependent: :destroy
17
18
  end
@@ -13,16 +13,18 @@
13
13
  <%= form.range_field :excellence %>
14
14
  <%= form.url_field :blog_url %>
15
15
  <%= form.color_field :favorite_color %>
16
- <%= form.select :fruit_id, options_for_select(::Fruit.pluck(:name, :id), form.object.fruit_id), {include_blank: "Select Favorite Fruit"} %>
16
+ <%= form.select :fruit_id, options_for_select(::Fruit.pluck(:name, :id), form.object.fruit_id),
17
+ {include_blank: "Select Favorite Fruit"} %>
17
18
  <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name do |b| %>
18
19
  <%= b.check_box + b.text %>
19
20
  <% end %>
20
21
  <%= form.fields_for :address, include_id: false do |address_form| %>
21
22
  <%= address_form.text_area :street %>
22
23
  <%= address_form.text_field :state %>
23
- <%= address_form.text_field :city %>
24
+ <%= address_form.grouped_collection_select :city, ::Country.all, :cities, :name, :id, :name %>
24
25
  <%= address_form.text_field :postal_code %>
25
- <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id), {include_blank: "Select Country", bootstrap_form: {}} %>
26
+ <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
27
+ {include_blank: "Select Country", bootstrap_form: {}} %>
26
28
  <% end %>
27
29
  <div class="mt-3">
28
30
  <%= form.submit "Register", class: "btn btn-primary" %>
@@ -0,0 +1,13 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ class CreateCities < ActiveRecord::Migration[7.0]
6
+ def change
7
+ create_table :cities do |t|
8
+ t.string :name
9
+ t.references :country
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
data/demo/db/schema.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema[7.0].define(version: 2023_05_14_061100) do
13
+ ActiveRecord::Schema[7.0].define(version: 2023_05_16_044126) do
14
14
  create_table "addresses", primary_key: "user_id", force: :cascade do |t|
15
15
  t.integer "country_id"
16
16
  t.string "street"
@@ -23,6 +23,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_14_061100) do
23
23
  t.index ["user_id"], name: "index_addresses_on_user_id"
24
24
  end
25
25
 
26
+ create_table "cities", force: :cascade do |t|
27
+ t.string "name"
28
+ t.integer "country_id"
29
+ t.datetime "created_at", null: false
30
+ t.datetime "updated_at", null: false
31
+ t.index ["country_id"], name: "index_cities_on_country_id"
32
+ end
33
+
26
34
  create_table "countries", force: :cascade do |t|
27
35
  t.string "name"
28
36
  t.datetime "created_at", null: false
data/demo/db/seeds.rb CHANGED
@@ -13,3 +13,10 @@ end
13
13
  ::Skill::DEFAULT_OPTIONS.each do |skill|
14
14
  ::Skill.find_or_create_by(name: skill)
15
15
  end
16
+
17
+ ::City::DEFAULT_OPTIONS.each do |country, cities|
18
+ country = ::Country.find_by(name: country)
19
+ country.present? && cities.each do |city|
20
+ country.cities.find_or_create_by(name: city)
21
+ end
22
+ end
@@ -66,6 +66,14 @@ module RailsBootstrapForm
66
66
  end
67
67
  end
68
68
 
69
+ def grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
70
+ options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
71
+
72
+ field_wrapper_builder(attribute, options, html_options) do
73
+ super(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
74
+ end
75
+ end
76
+
69
77
  def time_zone_select(attribute, priority_zones = nil, options = {}, html_options = {})
70
78
  options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
71
79
 
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.4.1".freeze
6
+ VERSION = "0.4.2".freeze
7
7
  REQUIRED_RAILS_VERSION = "~> 7.0".freeze
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harshal LADHE (shivam091)
@@ -56,6 +56,7 @@ files:
56
56
  - demo/app/mailers/application_mailer.rb
57
57
  - demo/app/models/address.rb
58
58
  - demo/app/models/application_record.rb
59
+ - demo/app/models/city.rb
59
60
  - demo/app/models/country.rb
60
61
  - demo/app/models/fruit.rb
61
62
  - demo/app/models/skill.rb
@@ -97,6 +98,7 @@ files:
97
98
  - demo/db/migrate/20230514055840_create_addresses.rb
98
99
  - demo/db/migrate/20230514060556_create_skills.rb
99
100
  - demo/db/migrate/20230514061100_create_user_skills.rb
101
+ - demo/db/migrate/20230516044126_create_cities.rb
100
102
  - demo/db/schema.rb
101
103
  - demo/db/seeds.rb
102
104
  - demo/public/favicon.ico