I am new to rails and I am creating a basic blog application.
When I have created a post it has an author. If you locate the author it displays a list of posts that have been created by that author on their own individual page. Each of these links can be selected.
I want to now create a link on each post page which displays the name of the author and then allows you to select this and go back to the author’s individual page.
So far I have added the following code to the pages view:
<%= link_to 'Back to List of Authors', authors_path %>
I’m now not sure how to change it so that instead if saying 'Back to List of Authors' it displays the authors name and allows it to be selected and takes the user back to the author’s individual page. Currently it takes you back to the complete list of authors and not in individual author.
Any advice will be appreciated.
Something like this should work:
This is working under the assumption that you have a instance variable
@postthat has the post data, and author belongs_to post.Of course a more verbose way is to explicitly state the route like so: