Add action Settings::PassportsController#create
This commit is contained in:
parent
44131ce7d3
commit
bb42e5069a
7 changed files with 71 additions and 3 deletions
|
@ -6,8 +6,9 @@ class Settings::PassportsController < ApplicationController
|
|||
before_action :skip_policy_scope, only: :index
|
||||
|
||||
before_action :set_account
|
||||
before_action :set_passport, only: :show
|
||||
before_action :new_passport, only: :new
|
||||
before_action :set_passport, only: :show
|
||||
before_action :new_passport, only: :new
|
||||
before_action :build_passport, only: :create
|
||||
|
||||
# GET /settings/passports
|
||||
def index
|
||||
|
@ -26,6 +27,15 @@ class Settings::PassportsController < ApplicationController
|
|||
authorize [:settings, Passport]
|
||||
end
|
||||
|
||||
# POST /settings/passports
|
||||
def create
|
||||
authorize [:settings, @passport]
|
||||
|
||||
return render :new unless @passport.save
|
||||
|
||||
redirect_to [:settings, @passport]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_account
|
||||
|
@ -39,4 +49,9 @@ private
|
|||
def new_passport
|
||||
@passport = Passport.new person: @account&.person
|
||||
end
|
||||
|
||||
def build_passport
|
||||
@passport = Passport.new permitted_attributes [:settings, Passport]
|
||||
@passport.person = @account&.person
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,4 +12,35 @@ class Settings::PassportPolicy < ApplicationPolicy
|
|||
def create?
|
||||
account&.person
|
||||
end
|
||||
|
||||
def permitted_attributes_for_create
|
||||
%i[
|
||||
last_name
|
||||
first_name
|
||||
middle_name
|
||||
sex
|
||||
date_of_birth
|
||||
place_of_birth
|
||||
series
|
||||
number
|
||||
issued_by
|
||||
unit_code
|
||||
date_of_issue
|
||||
zip_code
|
||||
town_type
|
||||
town_name
|
||||
settlement_type
|
||||
settlement_name
|
||||
district_type
|
||||
district_name
|
||||
street_type
|
||||
street_name
|
||||
residence_type
|
||||
residence_name
|
||||
building_type
|
||||
building_name
|
||||
apartment_type
|
||||
apartment_name
|
||||
].freeze
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,13 @@
|
|||
<%= simple_form_for [:settings, @passport] do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<%= f.input :last_name %>
|
||||
<%= f.input :first_name %>
|
||||
<%= f.input :middle_name %>
|
||||
<%= f.input :sex, collection: Passport.sexes.keys.map(&:to_sym) %>
|
||||
<%= f.input :date_of_birth, start_year: 1900, end_year: Time.zone.now.year %>
|
||||
<%= f.input :place_of_birth %>
|
||||
|
||||
<%= f.input :series %>
|
||||
<%= f.input :number %>
|
||||
<%= f.input :issued_by %>
|
||||
|
|
|
@ -11,6 +11,10 @@ en:
|
|||
error_notification:
|
||||
default_message: 'Please review the problems below:'
|
||||
options:
|
||||
passport:
|
||||
sex:
|
||||
male: Male
|
||||
female: Female
|
||||
person:
|
||||
sex:
|
||||
male: Male
|
||||
|
|
|
@ -11,6 +11,10 @@ ru:
|
|||
error_notification:
|
||||
default_message: 'Пожалуйста, исправьте следующие ошибки:'
|
||||
options:
|
||||
passport:
|
||||
sex:
|
||||
male: Мужской
|
||||
female: Женский
|
||||
person:
|
||||
sex:
|
||||
male: Мужской
|
||||
|
|
|
@ -35,7 +35,7 @@ Rails.application.routes.draw do
|
|||
resource :appearance, only: %i[edit update]
|
||||
resource :person, only: %i[show new]
|
||||
resources :sessions, only: :index
|
||||
resources :passports, only: %i[index show new]
|
||||
resources :passports, only: %i[index show new create]
|
||||
|
||||
resources :contacts, only: %i[index create destroy] do
|
||||
resource :security_notification_switch,
|
||||
|
|
7
spec/requests/settings/passports/create_spec.rb
Normal file
7
spec/requests/settings/passports/create_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'POST /settings/passports' do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Reference in a new issue