-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create article class, add and migrate db, add table with date, author…
… and content columns
- Loading branch information
1 parent
a8b7e4b
commit 3671bbb
Showing
6 changed files
with
63 additions
and
0 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
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 |
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,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 |
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,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 |
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,6 @@ | ||
#adding in author column to articles table | ||
class AddAuthorToArticles < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :articles, :author, :string | ||
end | ||
end |
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,6 @@ | ||
#adding in date column to articles table | ||
class AddDateToArticles < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :articles, :date, :datetime | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.