CRUD Application: Part 2
Learn to add the create and read functionality to our application and how to navigate between different views.
We'll cover the following...
So far, your app opens the index.html.erb
view for you and displays all the pets in our record as clickable links.
Next, we want to do the following:
- Edit
index.html.erb
to display a link to create a new pet. - Edit
new.html.erb
to display web forms to set attributes for the new pet. - Create a
create
method in yourapp/controllers/pets_controller.rb
file to handle the creation of a new pet. - Edit
show.html.erb
to display details of a pet when you click it.
Adding new pet
Edit the index view
In your app/views/pets/index.html.erb
file you need to add a link to take you to the new.html.erb
view, which will display the form to create a new pet.
To add the link, you will call the link_to
method, which will create a hyperlink based on given text and where to go.
<%= link_to 'New pet', new_pet_path %>
This will create a hyperlink with the text “New pet” and take you to new.html.erb
upon click.
...