add message model and migration

This commit is contained in:
bijan 2022-05-12 19:44:54 +04:30
parent a6721fed75
commit 0185ac276c
7 changed files with 67 additions and 3 deletions

View File

@ -0,0 +1,22 @@
ActiveAdmin.register Message do
csv do
column :title
column(:email)
column('bODY', humanize_name: false) # preserve case
end
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
# Uncomment all parameters which should be permitted for assignment
#
permit_params :title, :description, :email, :phone
#
# or
#
# permit_params do
# permitted = [:title, :description, :email, :phone]
# permitted << :other if params[:action] == 'create' && current_user.admin?
# permitted
# end
end

2
app/models/message.rb Normal file
View File

@ -0,0 +1,2 @@
class Message < ApplicationRecord
end

View File

@ -0,0 +1,11 @@
class CreateMessages < ActiveRecord::Migration[6.0]
def change
create_table :messages do |t|
t.string :title
t.text :description
t.string :email, null: false
t.string :phone
t.timestamps
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_05_12_124755) do
ActiveRecord::Schema.define(version: 2022_05_12_140948) do
create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace"
@ -38,4 +38,13 @@ ActiveRecord::Schema.define(version: 2022_05_12_124755) do
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
end
create_table "messages", force: :cascade do |t|
t.string "title"
t.text "description"
t.string "email", null: false
t.string "phone"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
end

View File

@ -5,5 +5,7 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password') if Rails.env.development?
AdminUser.create!(email: 'bijan@example.com', password: '1234567890', password_confirmation: '1234567890') if Rails.env.development?
if Rails.env.development?
AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password')
AdminUser.create!(email: 'bijan@example.com', password: '1234567890', password_confirmation: '1234567890')
end

11
test/fixtures/messages.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

View File

@ -0,0 +1,7 @@
require 'test_helper'
class MessageTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end