-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from ab-noori/feature/add-new-course-form
Creating the form for adding a new course 🚀
- Loading branch information
Showing
7 changed files
with
139 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
db/migrate/20231010183439_create_active_storage_tables.active_storage.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# This migration comes from active_storage (originally 20170806125915) | ||
class CreateActiveStorageTables < ActiveRecord::Migration[5.2] | ||
def change | ||
# Use Active Record's configured type for primary and foreign keys | ||
primary_key_type, foreign_key_type = primary_and_foreign_key_types | ||
|
||
create_table :active_storage_blobs, id: primary_key_type do |t| | ||
t.string :key, null: false | ||
t.string :filename, null: false | ||
t.string :content_type | ||
t.text :metadata | ||
t.string :service_name, null: false | ||
t.bigint :byte_size, null: false | ||
t.string :checksum | ||
|
||
if connection.supports_datetime_with_precision? | ||
t.datetime :created_at, precision: 6, null: false | ||
else | ||
t.datetime :created_at, null: false | ||
end | ||
|
||
t.index [ :key ], unique: true | ||
end | ||
|
||
create_table :active_storage_attachments, id: primary_key_type do |t| | ||
t.string :name, null: false | ||
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type | ||
t.references :blob, null: false, type: foreign_key_type | ||
|
||
if connection.supports_datetime_with_precision? | ||
t.datetime :created_at, precision: 6, null: false | ||
else | ||
t.datetime :created_at, null: false | ||
end | ||
|
||
t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true | ||
t.foreign_key :active_storage_blobs, column: :blob_id | ||
end | ||
|
||
create_table :active_storage_variant_records, id: primary_key_type do |t| | ||
t.belongs_to :blob, null: false, index: false, type: foreign_key_type | ||
t.string :variation_digest, null: false | ||
|
||
t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true | ||
t.foreign_key :active_storage_blobs, column: :blob_id | ||
end | ||
end | ||
|
||
private | ||
def primary_and_foreign_key_types | ||
config = Rails.configuration.generators | ||
setting = config.options[config.orm][:primary_key_type] | ||
primary_key_type = setting || :primary_key | ||
foreign_key_type = setting || :bigint | ||
[primary_key_type, foreign_key_type] | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,27 @@ | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) | ||
# Character.create(name: "Luke", movie: movies.first) | ||
# db/seeds.rb | ||
|
||
# Create sample users | ||
user1 = User.create(name: "John Doe") | ||
user2 = User.create(name: "Jane Smith") | ||
|
||
# Create an array of image URLs | ||
# image_urls = ['/course/database.png', '/course/web.png'] | ||
|
||
# Create sample courses | ||
course1 = Course.create( | ||
name: "Course 1", | ||
description: "Description for Course 1", | ||
image: "course1.jpg", | ||
fee: 100.0, | ||
startDate: Date.new(2023, 10, 10) | ||
) | ||
course2 = Course.create( | ||
name: "Course 2", | ||
description: "Description for Course 2", | ||
image: "course2.jpg", | ||
fee: 150.0, | ||
startDate: Date.new(2023, 11, 5) | ||
) | ||
# courses = [] | ||
# 6.times do |i| | ||
# courses << Course.create( | ||
# name: "Course #{i + 1}", | ||
# description: "Description for Course #{i + 1}", | ||
# image: image_urls[i % 2], # Alternating between the two images | ||
# fee: 100.0 + (i * 10), # Incrementing fee | ||
# startDate: Date.new(2023, 10, 10) + i.days # Incrementing start date | ||
# ) | ||
# end | ||
Course.create(name: 'course_1', description:'this is our first course', fee: 1200, startDate: "2023-04-04") | ||
|
||
course = Course.first | ||
|
||
# Create sample reservations associated with users and courses | ||
Reservation.create(user_id: user1.id, course_id: course1.id, city: "New York", date: Date.new(2023, 10, 12)) | ||
Reservation.create(user_id: user2.id, course_id: course2.id, city: "Los Angeles", date: Date.new(2023, 11, 8)) | ||
Reservation.create(user_id: user1.id, course_id: course.id, city: "New York", date: Date.new(2023, 10, 12)) | ||
Reservation.create(user_id: user2.id, course_id: course.id, city: "Los Angeles", date: Date.new(2023, 11, 8)) |