Skip to content

Commit

Permalink
Create article class, add and migrate db, add table with date, author…
Browse files Browse the repository at this point in the history
… and content columns
  • Loading branch information
ab-syntaxerror committed Jan 28, 2024
1 parent a8b7e4b commit 3671bbb
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#based off of the structure of the unit test article_test.rb,
#I'm creating an article class within the app/models directory
#that inherits from ActiveRecord::Base
#This is the class that will be used to create new articles
#in the database
class Article < ActiveRecord::Base
#Next, I need to add search functionality to this Article class. We can do this by using a method.
def self.search(query)
where("title LIKE ? OR content LIKE ?", "%#{query}%", "%#{query}%")
end
end
10 changes: 10 additions & 0 deletions db/migrate/20240128165415_create_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#creating a table in the database called create articles
class CreateArticles < ActiveRecord::Migration[6.0]
def change
create_table :articles do |t|
t.string :title
t.text :body
t.timestamps
end
end
end
6 changes: 6 additions & 0 deletions db/migrate/20240128170026_add_content_to_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Adding in the content column to the articles table
class AddContentToArticles < ActiveRecord::Migration[7.1]
def change
add_column :articles, :content, :text
end
end
6 changes: 6 additions & 0 deletions db/migrate/20240128170211_add_author_to_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#adding in author column to articles table
class AddAuthorToArticles < ActiveRecord::Migration[7.1]
def change
add_column :articles, :author, :string
end
end
6 changes: 6 additions & 0 deletions db/migrate/20240128170422_add_date_to_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#adding in date column to articles table
class AddDateToArticles < ActiveRecord::Migration[7.1]
def change
add_column :articles, :date, :datetime
end
end
24 changes: 24 additions & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3671bbb

Please sign in to comment.