-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from rubenbe/master
fix nested select when used inside a nested form
- Loading branch information
Showing
10 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
AllCops: | ||
Exclude: | ||
- "vendor/**/*" | ||
- "spec/dummy/db/*" | ||
- "db/**/*" | ||
- "bin/**/*" | ||
DisplayCopNames: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
ActiveAdmin.register Department do | ||
permit_params :name, departments_cities_attributes: [:id, :city_id, :_destroy] | ||
|
||
form do |f| | ||
f.inputs do | ||
f.input :name | ||
end | ||
f.inputs do | ||
f.has_many :departments_cities, allow_destroy: true do |city| | ||
city.input :city_id, as: :nested_select, required: true, | ||
level_1: { attribute: :country_id }, | ||
level_2: { attribute: :region_id }, | ||
level_3: { attribute: :city_id } | ||
end | ||
end | ||
f.actions | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Department < ActiveRecord::Base | ||
has_many :departments_cities | ||
accepts_nested_attributes_for :departments_cities, allow_destroy: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class DepartmentsCity < ActiveRecord::Base | ||
has_many :departments | ||
has_many :cities | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateDepartments < ActiveRecord::Migration | ||
def change | ||
create_table :departments do |t| | ||
t.string :name | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/dummy/db/migrate/20180228122115_create_departments_cities.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class CreateDepartmentsCities < ActiveRecord::Migration | ||
def change | ||
create_table :departments_cities do |t| | ||
t.references :department, index: true, foreign_key: true | ||
t.references :city, index: true, foreign_key: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters