Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics Introduction to ActiveRecord A Quick and Dirty Example

Route to 'all posts'

Hey!

I'm just playing with a simple back button.

When I'm on an individual post page, I want to navigate back to all posts through a "link_to". I'm not sure if it's the best way, but it's the way I want to try!

So I've followed the link_to(post) syntax and tried

<%= link_to "Back", post_path(posts) %>

because running rake routes shows

Prefix Verb   URI Pattern               Controller#Action
posts GET    /posts(.:format)          posts#index
post GET    /posts/:id(.:format)      posts#show

So I just swapped out (post) with (posts)... I hope this makes sense - essentially I want to write a link_to to the posts page.

The error I get is undefined local variable or method `posts'

Thanks!

Thomas

1 Answer

Stone Preston
Stone Preston
42,016 Points

maybe try:

<%= link_to "Back", posts_path%>

perfect, thanks!