Member-only story

Getting Started With Rails Part 3

Steven Klavins
4 min readMay 23, 2020

Ok after completing part 2 we can now see each article rendered as it was added, however, we now need a way to see a list of articles. The first thing I have done is added a new method to the index articles controller, this method retrieves all of our articles using Article.all.

As we did before; we now create the HTML for index and use the values from @articles to list them.

Here we create a loop using Ruby’s each do loop to render each article in the page, each time we pass through this loop we take one of the articles from the database. As we do this we include the article title, text, and a link to the article itself, this is done by passing it back to the show method we previously made.

Here is the result when visiting our localhost/articles…

Now to add some links so we can navigate around the application, Rails conveniently has a helper method called link_to. I added a link for the new article page in the articles index, a link to the articles list in the welcome index, a return link on the create a new article page, and a return link on each individual article.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Steven Klavins
Steven Klavins

Written by Steven Klavins

Hi, I’m Steven, most call me Steve! I’m a programmer, musician, and artist. This blog contains various tutorials and posts related to software development.

No responses yet

Write a response