rails_bootstrap_form 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25354c2cb11c5971bf3435e2415ca37c0fcfabeeb45cd269a8dbecba7d582fd7
4
- data.tar.gz: f695f139348b6fb1f2c054e90f79c6d5c53805ec047ac6d239df946a09039278
3
+ metadata.gz: 5874a38745d73c1b0bb05c751711cdc380be8684c71187069e07224e9d40333a
4
+ data.tar.gz: ffe2043c13700e6015d7741b51550c52642098c412f29b1921a7e98ed20ec9cf
5
5
  SHA512:
6
- metadata.gz: ed91e2feb0354818a43161b165ed8bba83b8e29a9f3013d2a3f7df54e23158768332d2381f36132399dedb7531a65abcd9234a70814c9b05f63c6af3ed66c245
7
- data.tar.gz: ea1cf098b34f86c6f5ca4bb1cfc6031a93f81865515e484f6322934e33673b9980c053ccf02db70d302feb520e8766998678505f3e406b805b426dada7d000ee
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.0)
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
@@ -40,7 +40,7 @@ module RailsBootstrapForm
40
40
 
41
41
  DATE_SELECT_HELPERS.each do |field_tag_name|
42
42
  define_method(field_tag_name) do |attribute, options = {}, html_options = {}, &block|
43
- options = options.reverse_merge(bootstrap_form: {field_class: "form-select"})
43
+ options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
44
44
 
45
45
  field_wrapper_builder(attribute, options, html_options) do
46
46
  tag.div(class: control_specific_class(field_tag_name)) do
@@ -51,7 +51,7 @@ module RailsBootstrapForm
51
51
  end
52
52
 
53
53
  def select(attribute, choices = nil, options = {}, html_options = {}, &block)
54
- options = options.reverse_merge(bootstrap_form: {field_class: "form-select"})
54
+ options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
55
55
 
56
56
  field_wrapper_builder(attribute, options, html_options) do
57
57
  super(attribute, choices, options, html_options, &block)
@@ -59,34 +59,42 @@ module RailsBootstrapForm
59
59
  end
60
60
 
61
61
  def collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {})
62
- options = options.reverse_merge(bootstrap_form: {field_class: "form-select"})
62
+ options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
63
63
 
64
64
  field_wrapper_builder(attribute, options, html_options) do
65
65
  super(attribute, collection, value_method, text_method, options, html_options)
66
66
  end
67
67
  end
68
68
 
69
- def range_field(attribute, options = {})
70
- options = options.reverse_merge(bootstrap_form: {field_class: "form-range"})
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
71
 
72
- field_wrapper_builder(attribute, options) do
73
- super(attribute, options)
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
74
  end
75
75
  end
76
76
 
77
- def color_field(attribute, options = {})
78
- options = options.reverse_merge(bootstrap_form: {field_class: "form-control form-control-color"})
77
+ def time_zone_select(attribute, priority_zones = nil, options = {}, html_options = {})
78
+ options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
79
+
80
+ field_wrapper_builder(attribute, options, html_options) do
81
+ super(attribute, priority_zones, options, html_options)
82
+ end
83
+ end
84
+
85
+ def range_field(attribute, options = {})
86
+ options = {bootstrap_form: {field_class: "form-range"}}.deep_merge!(options)
79
87
 
80
88
  field_wrapper_builder(attribute, options) do
81
89
  super(attribute, options)
82
90
  end
83
91
  end
84
92
 
85
- def time_zone_select(attribute, priority_zones = nil, options = {}, html_options = {})
86
- options = options.reverse_merge(bootstrap_form: {field_class: "form-select"})
93
+ def color_field(attribute, options = {})
94
+ options = {bootstrap_form: {field_class: "form-control form-control-color"}}.deep_merge!(options)
87
95
 
88
- field_wrapper_builder(attribute, options, html_options) do
89
- super(attribute, priority_zones, options, html_options)
96
+ field_wrapper_builder(attribute, options) do
97
+ super(attribute, options)
90
98
  end
91
99
  end
92
100
 
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.4.0".freeze
6
+ VERSION = "0.4.2".freeze
7
7
  REQUIRED_RAILS_VERSION = "~> 7.0".freeze
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harshal LADHE (shivam091)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-15 00:00:00.000000000 Z
11
+ date: 2023-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec
@@ -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