Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
undefined local variable or method `page' for #<#<Class:0x007ff2ba33ba30>:0x007ff2bc0c61e0> Did you mean? @pages
What is wrong with this code?
<h1>Blog Pages</h1> <% @pages.each do |t| %> <p><%= link_to t.title, page_path(page) %></p> <% end %>
Rails.application.routes.draw do resources :posts # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html get '/pages', to: 'pages#index' get '/pages/:id', to: 'pages#show', as: 'page' end
Maciej Czuchnowski36,440 Points
page_path(page) you're using a
page variable that isn't defined anywhere. Since you're iterating through a @pages collection, I assume you wanted to name each instance as
page, but instead they are named
page_path(t) would probably work.
To make it more readable and more in-line with what is shown in the video, you probably want the code to look more like this:
<% @pages.each do |page| %> <p><%= link_to page.title, page_path(page) %></p> <% end %>
Ari Misha19,274 Points
Hiya Rick! Can you post your controller code especially "show" controller? And hey while you're at it , please consider using markdown cheatsheet in order for other programmers to go through it without the code looking cluttery and messy.
Vladislav Trotsenko9,291 Points
With your case:
<% @pages.each do |t| %> <p><%= link_to(t.title, t) %></p> <% end %>