In this new task, we will add associations to the Post
model for categorization and ensure that each post has an author.
Task 6
Let's incorporate the following functionalities into the application:
- Create an
Organization
model with a name
attribute. Migrate the database
and add an entry for a sample organization through the Rails console.
- Add a
User
model with attributes name
, email
and password_digest
. It
is recommended that candidates utilize the bcrypt
gem for secure password
hashing. Additionally, include a foreign key referencing the Organization
model within the User
model. So, every user should belong to an
organization.
- In the
Organization
model, the name
attribute should not be NULL. In the
User
model, proper validations for name
, email
, password
and
password_confirmation
should be added.
- Create a Category model with a
name
attribute. Each post can be associated with more than one category.
- Modify the
Post
model by adding foreign keys that reference both the User
and Organization
models. Additionally, the Post
model should have an association with the Category
model to allow each post to be linked to multiple categories. This will ensure that each post has an author, is associated with an organization, and can have various categories.
- Modify the post listing page to display the name of the author and the categories associated with each post card.