mirror of
https://github.com/internetee/registry.git
synced 2025-07-04 02:03:36 +02:00
Add contry select to user form
This commit is contained in:
parent
f76d73c597
commit
0dc0cc63d9
6 changed files with 16 additions and 16 deletions
|
@ -43,6 +43,6 @@ class Admin::UsersController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:username, :password, :identity_code, :email, :registrar_id, :admin, :registrar_typeahead)
|
params.require(:user).permit(:username, :password, :identity_code, :email, :registrar_id, :admin, :registrar_typeahead, :country_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,12 +8,14 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :role
|
belongs_to :role
|
||||||
belongs_to :registrar
|
belongs_to :registrar
|
||||||
|
belongs_to :country
|
||||||
|
|
||||||
validates :username, :password, presence: true
|
validates :username, :password, presence: true
|
||||||
validates :identity_code, uniqueness: true, allow_blank: true
|
validates :identity_code, uniqueness: true, allow_blank: true
|
||||||
validate :registrar_presence
|
validates :identity_code, presence: true, if: -> { country.iso == 'EE' && identity_code.blank? }
|
||||||
|
validates :registrar, presence: true, if: -> { !admin && !registrar }
|
||||||
|
|
||||||
before_save :manage_registrar
|
before_save -> { self.registrar = nil if admin? }
|
||||||
|
|
||||||
attr_accessor :registrar_typeahead
|
attr_accessor :registrar_typeahead
|
||||||
|
|
||||||
|
@ -24,16 +26,4 @@ class User < ActiveRecord::Base
|
||||||
def registrar_typeahead
|
def registrar_typeahead
|
||||||
@registrar_typeahead || registrar || nil
|
@registrar_typeahead || registrar || nil
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def registrar_presence
|
|
||||||
if !admin && !registrar
|
|
||||||
errors.add(:registrar, :blank)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def manage_registrar
|
|
||||||
self.registrar = nil if admin?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :password
|
= f.label :password
|
||||||
= f.text_field(:password, class: 'form-control')
|
= f.text_field(:password, class: 'form-control')
|
||||||
|
.form-group
|
||||||
|
= f.label :country_id
|
||||||
|
= f.collection_select :country_id, Country.all, :id, :name, {}, { class: 'form-control' }
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :identity_code
|
= f.label :identity_code
|
||||||
= f.text_field(:identity_code, class: 'form-control')
|
= f.text_field(:identity_code, class: 'form-control')
|
||||||
|
|
|
@ -164,6 +164,7 @@ en:
|
||||||
password:
|
password:
|
||||||
blank: 'Password is missing'
|
blank: 'Password is missing'
|
||||||
identity_code:
|
identity_code:
|
||||||
|
blank: 'Identity code is missing'
|
||||||
taken: 'Identity code already exists'
|
taken: 'Identity code already exists'
|
||||||
email:
|
email:
|
||||||
blank: 'Email is missing'
|
blank: 'Email is missing'
|
||||||
|
|
5
db/migrate/20140930093039_add_country_to_users.rb
Normal file
5
db/migrate/20140930093039_add_country_to_users.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddCountryToUsers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :users, :country_id, :integer
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20140929095329) do
|
ActiveRecord::Schema.define(version: 20140930093039) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -200,6 +200,7 @@ ActiveRecord::Schema.define(version: 20140929095329) do
|
||||||
t.boolean "admin", default: false
|
t.boolean "admin", default: false
|
||||||
t.string "identity_code"
|
t.string "identity_code"
|
||||||
t.integer "registrar_id"
|
t.integer "registrar_id"
|
||||||
|
t.integer "country_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue