1
0
Fork 0

Add action PassportsController#create

This commit is contained in:
Alex Kotov 2018-11-30 09:07:45 +05:00
parent 369d01f650
commit 8604829a56
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
5 changed files with 48 additions and 2 deletions

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
class PassportsController < ApplicationController
before_action :set_passport, except: :index
before_action :set_passport, except: %i[index new create]
# GET /passports
def index
@ -13,6 +13,12 @@ class PassportsController < ApplicationController
authorize @passport
end
# GET /passports/new
def new
@passport = Passport.new
authorize @passport
end
private
def set_passport

View File

@ -5,6 +5,10 @@ class PassportPolicy < ApplicationPolicy
true
end
def create?
true
end
def permitted_attributes_for_create
%i[
surname given_name patronymic sex date_of_birth place_of_birth series

View File

@ -0,0 +1,23 @@
<div class="container">
<%= simple_form_for @passport do |f| %>
<%= f.input :surname %>
<%= f.input :given_name %>
<%= f.input :patronymic %>
<%= f.input :sex,
as: :radio_buttons,
collection: Passport.sexes.map { |k, v|
[Passport.human_attribute_name("sex.#{k}"), v]
} %>
<%= f.input :date_of_birth, start_year: Date.today.year - 150,
end_year: Date.today.year %>
<%= f.input :place_of_birth %>
<%= f.input :series %>
<%= f.input :number %>
<%= f.input :issued_by %>
<%= f.input :unit_code %>
<%= f.input :date_of_issue, start_year: Date.today.year - 150,
end_year: Date.today.year %>
<%= f.button :submit %>
<% end %>
</div>

View File

@ -28,7 +28,7 @@ Rails.application.routes.draw do
resources :membership_applications, only: %i[new create]
resources :passports, only: %i[index show]
resources :passports, only: %i[index show new create]
resources :telegram_bot_updates, only: :create
end

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'GET /passports/new' do
before do
get '/passports/new'
end
specify do
expect(response).to have_http_status :ok
end
end