add currency entity
This commit is contained in:
5
app/controllers/admin/currencies_controller.rb
Normal file
5
app/controllers/admin/currencies_controller.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
module Admin
|
||||||
|
class CurrenciesController < Admin::ApplicationController
|
||||||
|
end
|
||||||
|
end
|
||||||
52
app/dashboards/currency_dashboard.rb
Normal file
52
app/dashboards/currency_dashboard.rb
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
require "administrate/base_dashboard"
|
||||||
|
|
||||||
|
class CurrencyDashboard < Administrate::BaseDashboard
|
||||||
|
# ATTRIBUTE_TYPES
|
||||||
|
# a hash that describes the type of each of the model's fields.
|
||||||
|
#
|
||||||
|
# Each different type represents an Administrate::Field object,
|
||||||
|
# which determines how the attribute is displayed
|
||||||
|
# on pages throughout the dashboard.
|
||||||
|
ATTRIBUTE_TYPES = {
|
||||||
|
id: Field::Number,
|
||||||
|
name: Field::String,
|
||||||
|
created_at: Field::DateTime,
|
||||||
|
updated_at: Field::DateTime,
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
# COLLECTION_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed on the model's index page.
|
||||||
|
#
|
||||||
|
# By default, it's limited to four items to reduce clutter on index pages.
|
||||||
|
# Feel free to add, remove, or rearrange items.
|
||||||
|
COLLECTION_ATTRIBUTES = [:id, :name, :created_at, :updated_at].freeze
|
||||||
|
|
||||||
|
# SHOW_PAGE_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed on the model's show page.
|
||||||
|
SHOW_PAGE_ATTRIBUTES = [:id, :name, :created_at, :updated_at].freeze
|
||||||
|
|
||||||
|
# FORM_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed
|
||||||
|
# on the model's form (`new` and `edit`) pages.
|
||||||
|
FORM_ATTRIBUTES = [:name].freeze
|
||||||
|
|
||||||
|
# COLLECTION_FILTERS
|
||||||
|
# a hash that defines filters that can be used while searching via the search
|
||||||
|
# field of the dashboard.
|
||||||
|
#
|
||||||
|
# For example to add an option to search for open resources by typing "open:"
|
||||||
|
# in the search field:
|
||||||
|
#
|
||||||
|
# COLLECTION_FILTERS = {
|
||||||
|
# open: ->(resources) { resources.where(open: true) }
|
||||||
|
# }.freeze
|
||||||
|
COLLECTION_FILTERS = {}.freeze
|
||||||
|
|
||||||
|
# Overwrite this method to customize how currencies are displayed
|
||||||
|
# across all pages of the admin dashboard.
|
||||||
|
#
|
||||||
|
# def display_resource(currency)
|
||||||
|
# "Currency ##{currency.id}"
|
||||||
|
# end
|
||||||
|
end
|
||||||
14
app/models/currency.rb
Normal file
14
app/models/currency.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: currencies
|
||||||
|
#
|
||||||
|
# id :bigint not null, primary key
|
||||||
|
# name :string not null
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
#
|
||||||
|
class Currency < ApplicationRecord
|
||||||
|
validates :name, presence: true
|
||||||
|
end
|
||||||
@@ -6,6 +6,7 @@ Rails.application.routes.draw do
|
|||||||
namespace :admin do
|
namespace :admin do
|
||||||
resources :users
|
resources :users
|
||||||
resources :user_documents
|
resources :user_documents
|
||||||
|
resources :currencies
|
||||||
resources :admin_users
|
resources :admin_users
|
||||||
|
|
||||||
root to: "users#index"
|
root to: "users#index"
|
||||||
|
|||||||
10
db/migrate/20210811014107_create_currencies.rb
Normal file
10
db/migrate/20210811014107_create_currencies.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
class CreateCurrencies < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
create_table(:currencies) do |t|
|
||||||
|
t.string(:name, null: false)
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
8
db/schema.rb
generated
8
db/schema.rb
generated
@@ -10,7 +10,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: 2021_08_08_153626) do
|
ActiveRecord::Schema.define(version: 2021_08_11_014107) 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"
|
||||||
@@ -55,6 +55,12 @@ ActiveRecord::Schema.define(version: 2021_08_08_153626) do
|
|||||||
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
|
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "currencies", force: :cascade do |t|
|
||||||
|
t.string "name", null: false
|
||||||
|
t.datetime "created_at", precision: 6, null: false
|
||||||
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "user_documents", force: :cascade do |t|
|
create_table "user_documents", force: :cascade do |t|
|
||||||
t.string "status", null: false
|
t.string "status", null: false
|
||||||
t.bigint "user_id", null: false
|
t.bigint "user_id", null: false
|
||||||
|
|||||||
18
spec/models/currency_spec.rb
Normal file
18
spec/models/currency_spec.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: currencies
|
||||||
|
#
|
||||||
|
# id :bigint not null, primary key
|
||||||
|
# name :string not null
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
#
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
RSpec.describe(Currency, type: :model) do
|
||||||
|
describe "validations" do
|
||||||
|
it { is_expected.to(validate_presence_of(:name)) }
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user