Create Book Model
Closed this issue · 2 comments
vanderleipinto commented
Create a Book Model using scaffold.
rails g scaffold Books name:string description:text author:references
Thus we'll have the complete MVC for this entity including the routes.
The book belongs to an Author.
- Create the entity
- Migrate the database
- Insert the link in the navbar
- Change the model acorrding to the relationship of the Database
- Change the view archive to show the other related entity. (EX insert book with one Author)
vanderleipinto commented
Create the entity
rails g scaffold Books name:string description:text author:references
Migrate database
rails db:migrate
Insert the link in navbar
Added the following lines to do this:
<div class="Books" style="padding: 10px">
<%= link_to "Books", books_path %>
</div>
Change the view archive to show the other related entity
Added the following lines to do this:
<div class="field">
<%= form.label :author_id, style: "display: block" %>
<%= form.collection_select :author_id, Author.all, :id, :name, prompt: 'Select author' %>
</div>
It will create a select to choose the author by name.
vanderleipinto commented
Changed Books.name to Books.title in this issue