Ruby on Rails Error: The error occurred while evaluating nil.each -


i'm trying learn ruby geep getting error:

the error occurred while evaluating nil.each

i reading here "getting started" guide http://guides.rubyonrails.org/getting_started.html

here's piece of code index.html.erb:

<h1>listing snippets</h1> <div class="snippets"> <% @posts.each |post| %>     <h2><%= post.title %></h2>     <p><%= link_to 'view', post %> | <%= link_to 'edit', edit_post_path(post) %> | <%= link_to 'delete', post, :confirm => 'are sure?', :method => :delete %></p> <% end %> </div> 

now @posts var in posts_controller.rb

def index     @posts = post.all      respond_to |format|       format.html # index.html.erb       format.xml  { render :xml => @posts }     end   end 

what doing wrong? thanks.

ps: see displayed here http://127.0.0.1:3000/posts if want display them in root folder (http://127.0.0.1:3000/)

you should make partial , put post logic inside of it.

then can put on view long initialize collection inside of each used controller action.

so in home controller you'd still need:

@posts = post.find(:all) 

as far first question, try finding them via @posts = post.find(:all)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -