Refactor deprecated in rails 6.1 issues

This commit is contained in:
Alex Sherman 2021-05-03 13:40:42 +05:00
parent 83f3e14330
commit 39bbe6e06d
10 changed files with 122 additions and 50 deletions

View file

@ -34,7 +34,7 @@ module Admin
params[:admin_user].delete(:password) if params[:admin_user][:password].blank? params[:admin_user].delete(:password) if params[:admin_user][:password].blank?
params[:admin_user].delete(:password_confirmation) if params[:admin_user][:password_confirmation].blank? params[:admin_user].delete(:password_confirmation) if params[:admin_user][:password_confirmation].blank?
if @admin_user.update_attributes(admin_user_params) if @admin_user.update(admin_user_params)
flash[:notice] = I18n.t('record_updated') flash[:notice] = I18n.t('record_updated')
redirect_to [:admin, @admin_user] redirect_to [:admin, @admin_user]
else else

View file

@ -0,0 +1,32 @@
module SortedCountryHelper
def all_country_options(selected = nil)
quick_options = options_for_select(quick_list, selected: selected)
# no double select
selected = quick_list.map(&:second).include?(selected) ? '' : selected
all_options = options_for_select([['---', '---']] + all_sorted_truncated,
selected: selected, disabled: ['---'])
quick_options + all_options
end
def quick_list
[
%w[Estonia EE],
%w[Finland FI],
%w[Latvia LV],
%w[Lithuania LT],
['Russian Federation', 'RU'],
%w[Sweden SE],
['United States', 'US'],
]
end
def all_sorted
Country.all.sort_by(&:name)
end
def all_sorted_truncated
all_sorted.map { |country| [country.name.truncate(26), country.alpha2] }
end
end

View file

@ -1,40 +0,0 @@
class SortedCountry
class << self
include ActionView::Helpers
def all_options(selected = nil)
quick_options = options_for_select(quick_list, selected: selected)
# no double select
selected = quick_list.map(&:second).include?(selected) ? '' : selected
all_options = options_for_select([['---', '---']] + all_sorted_truncated,
selected: selected, disabled: ['---'])
quick_options + all_options
end
private
def quick_list
@quick_list ||=
[
%w[Estonia EE],
%w[Finland FI],
%w[Latvia LV],
%w[Lithuania LT],
['Russian Federation', 'RU'],
%w[Sweden SE],
['United States', 'US']
]
end
def all_sorted
@all_sorted ||= Country.all.sort_by(&:name)
end
def all_sorted_truncated
@all_sorted_truncated ||=
all_sorted.map { |country| [country.name.truncate(26), country.alpha2] }
end
end
end

View file

@ -35,14 +35,14 @@
.col-md-4.control-label .col-md-4.control-label
= f.label :country_code, t(:country), class: 'required' = f.label :country_code, t(:country), class: 'required'
.col-md-8 .col-md-8
= f.select :country_code, SortedCountry.all_options(f.object.country_code), {}, required: true, class: 'form-control' = f.select :country_code, ApplicationController.helpers.all_country_options(f.object.country_code), {}, required: true, class: 'form-control'
%hr %hr
.form-group .form-group
.col-md-4.control-label .col-md-4.control-label
= f.label :role, nil, class: 'required' = f.label :role, nil, class: 'required'
.col-md-8 .col-md-8
= select_tag 'admin_user[roles][]', = select_tag 'admin_user[roles][]',
options_for_select(AdminUser::ROLES.map {|x| [t(x), x] }, options_for_select(AdminUser::ROLES.map {|x| [t(x), x] },
@admin_user.roles.try(:first)), class: 'form-control selectize' @admin_user.roles.try(:first)), class: 'form-control selectize'
%hr %hr

View file

@ -28,7 +28,7 @@
.col-md-3 .col-md-3
.form-group .form-group
= label_tag t(:country) = label_tag t(:country)
= select_tag '[q][country_code_eq]', SortedCountry.all_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } = select_tag '[q][country_code_eq]', ApplicationController.helpers.all_country_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' }
.col-md-6 .col-md-6
.form-group .form-group
= label_tag t(:contact_type) = label_tag t(:contact_type)

View file

@ -49,7 +49,7 @@
</div> </div>
<div class="col-md-7"> <div class="col-md-7">
<%= f.select :address_country_code, <%= f.select :address_country_code,
SortedCountry.all_options(f.object.address_country_code), {}, ApplicationController.helpers.all_country_options(f.object.address_country_code), {},
required: true, class: 'form-control' %> required: true, class: 'form-control' %>
<span class="help-block"><%= t '.country_hint' %></span> <span class="help-block"><%= t '.country_hint' %></span>
</div> </div>
@ -59,4 +59,4 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -40,7 +40,7 @@
<div class="col-md-3"> <div class="col-md-3">
<div class="form-group"> <div class="form-group">
<%= label_tag t(:country) %> <%= label_tag t(:country) %>
<%= select_tag '[q][country_code_eq]', SortedCountry.all_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } %> <%= select_tag '[q][country_code_eq]', ApplicationController.helpers.all_country_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } %>
</div> </div>
</div> </div>

View file

@ -31,6 +31,6 @@
= f.label :country_code, t(:country) + '*' = f.label :country_code, t(:country) + '*'
.col-md-7 .col-md-7
- country_selected = f.object.persisted? ? f.object.country_code : 'EE' - country_selected = f.object.persisted? ? f.object.country_code : 'EE'
= f.select(:country_code, SortedCountry.all_options(country_selected), = f.select(:country_code, SApplicationController.helpers.all_country_options(country_selected),
{ include_blank: true }, required: true) { include_blank: true }, required: true)

View file

@ -19,7 +19,7 @@
= Country.new(f.object.ident_country_code).try(:to_s) = Country.new(f.object.ident_country_code).try(:to_s)
= " [#{f.object.ident_country_code}]" = " [#{f.object.ident_country_code}]"
- else - else
= f.select(:ident_country_code, SortedCountry.all_options(country_selected), {}, = f.select(:ident_country_code, ApplicationController.helpers.all_country_options(country_selected), {},
class: 'js-ident-country-code', required: true) class: 'js-ident-country-code', required: true)
.form-group .form-group

View file

@ -536,6 +536,43 @@ CREATE SEQUENCE public.certificates_id_seq
ALTER SEQUENCE public.certificates_id_seq OWNED BY public.certificates.id; ALTER SEQUENCE public.certificates_id_seq OWNED BY public.certificates.id;
--
-- Name: contact_requests; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.contact_requests (
id integer NOT NULL,
whois_record_id integer NOT NULL,
secret character varying NOT NULL,
email character varying NOT NULL,
name character varying NOT NULL,
valid_to timestamp without time zone NOT NULL,
status character varying DEFAULT 'new'::character varying NOT NULL,
ip_address inet,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
message_id character varying
);
--
-- Name: contact_requests_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.contact_requests_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: contact_requests_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.contact_requests_id_seq OWNED BY public.contact_requests.id;
-- --
-- Name: contacts; Type: TABLE; Schema: public; Owner: - -- Name: contacts; Type: TABLE; Schema: public; Owner: -
-- --
@ -2735,6 +2772,13 @@ ALTER TABLE ONLY public.bounced_mail_addresses ALTER COLUMN id SET DEFAULT nextv
ALTER TABLE ONLY public.certificates ALTER COLUMN id SET DEFAULT nextval('public.certificates_id_seq'::regclass); ALTER TABLE ONLY public.certificates ALTER COLUMN id SET DEFAULT nextval('public.certificates_id_seq'::regclass);
--
-- Name: contact_requests id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.contact_requests ALTER COLUMN id SET DEFAULT nextval('public.contact_requests_id_seq'::regclass);
-- --
-- Name: contacts id; Type: DEFAULT; Schema: public; Owner: - -- Name: contacts id; Type: DEFAULT; Schema: public; Owner: -
-- --
@ -3193,6 +3237,14 @@ ALTER TABLE ONLY public.certificates
ADD CONSTRAINT certificates_pkey PRIMARY KEY (id); ADD CONSTRAINT certificates_pkey PRIMARY KEY (id);
--
-- Name: contact_requests contact_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.contact_requests
ADD CONSTRAINT contact_requests_pkey PRIMARY KEY (id);
-- --
-- Name: contacts contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- Name: contacts contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- --
@ -3780,6 +3832,34 @@ CREATE INDEX index_accounts_on_registrar_id ON public.accounts USING btree (regi
CREATE INDEX index_certificates_on_api_user_id ON public.certificates USING btree (api_user_id); CREATE INDEX index_certificates_on_api_user_id ON public.certificates USING btree (api_user_id);
--
-- Name: index_contact_requests_on_email; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_contact_requests_on_email ON public.contact_requests USING btree (email);
--
-- Name: index_contact_requests_on_ip_address; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_contact_requests_on_ip_address ON public.contact_requests USING btree (ip_address);
--
-- Name: index_contact_requests_on_secret; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_contact_requests_on_secret ON public.contact_requests USING btree (secret);
--
-- Name: index_contact_requests_on_whois_record_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_contact_requests_on_whois_record_id ON public.contact_requests USING btree (whois_record_id);
-- --
-- Name: index_contacts_on_code; Type: INDEX; Schema: public; Owner: - -- Name: index_contacts_on_code; Type: INDEX; Schema: public; Owner: -
-- --