1
0
Fork 0

Add action Settings::PassportsController#new

This commit is contained in:
Alex Kotov 2020-04-10 18:28:34 +05:00
parent e3f410c223
commit 44131ce7d3
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
6 changed files with 70 additions and 1 deletions

View file

@ -7,6 +7,7 @@ class Settings::PassportsController < ApplicationController
before_action :set_account
before_action :set_passport, only: :show
before_action :new_passport, only: :new
# GET /settings/passports
def index
@ -20,6 +21,11 @@ class Settings::PassportsController < ApplicationController
authorize [:settings, @passport]
end
# GET /settings/passports/new
def new
authorize [:settings, Passport]
end
private
def set_account
@ -29,4 +35,8 @@ private
def set_passport
@passport = Passport.find params[:id]
end
def new_passport
@passport = Passport.new person: @account&.person
end
end

View file

@ -8,4 +8,8 @@ class Settings::PassportPolicy < ApplicationPolicy
def show?
account&.person && record.person == account.person
end
def create?
account&.person
end
end

View file

@ -5,6 +5,17 @@
</div>
<div class="col-md-9">
<% if policy([:settings, Passport]).new? %>
<div class="btn-group mb-3" role="group">
<% if policy([:settings, Passport]).new? %>
<%= link_to translate(:create),
new_settings_passport_path,
class: 'btn btn-primary',
role: :button %>
<% end %>
</div>
<% end %>
<%= render partial: 'table', locals: { passports: @passports } %>
<%= pagination @passports %>
</div>

View file

@ -0,0 +1,37 @@
<div class="container">
<div class="row">
<div class="col-md-3 mb-4">
<%= render partial: 'settings/nav_sidebar', locals: { tab: :passports } %>
</div>
<div class="col-md-9">
<%= simple_form_for [:settings, @passport] do |f| %>
<%= f.error_notification %>
<%= f.input :series %>
<%= f.input :number %>
<%= f.input :issued_by %>
<%= f.input :unit_code %>
<%= f.input :date_of_issue %>
<%= f.input :zip_code %>
<%= f.input :town_type %>
<%= f.input :town_name %>
<%= f.input :settlement_type %>
<%= f.input :settlement_name %>
<%= f.input :district_type %>
<%= f.input :district_name %>
<%= f.input :street_type %>
<%= f.input :street_name %>
<%= f.input :residence_type %>
<%= f.input :residence_name %>
<%= f.input :building_type %>
<%= f.input :building_name %>
<%= f.input :apartment_type %>
<%= f.input :apartment_name %>
<%= f.button :submit %>
<% end %>
</div>
</div>
</div>

View file

@ -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]
resources :passports, only: %i[index show new]
resources :contacts, only: %i[index create destroy] do
resource :security_notification_switch,

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'GET /settings/passports/new' do
pending "add some examples to (or delete) #{__FILE__}"
end