2014-01-23 60 views
0

嗨即時通訊新的紅寶石在軌道上。並遵循用戶指南。我得到了一些錯誤。我試圖搜索這個,但我找到了一個。問題是我們都有同樣的錯誤,但是當我試圖改變@posts = Post.all時,我仍然有一些錯誤,有人可以幫助我嗎?下面是我的代碼。 這是我post_controller.rbNoMethodError在帖子中#index

class PostsController < ApplicationController 
    def index 
    @posts = Post.all 
    end 

    def new 

    end 

    def create 
    #render text: params[:post].inspect 
    @post = Post.new(post_params) 

    @post.save 
    redirect_to @post 
    end 

    def show 
    @post = Post.find(params[:id]) 
    end 

    private 
    def post_params 
     params.require(:post).permit(:title, :text) 
    end 

end 

而且我index.html.erb

<h1>Listings!</h1> 
    <table> 
    <tr> 
     <th>Title</th> 
     <th>Text</th> 
    </tr> 
    <tr> 
     <% @posts.each do |posts| %> 
     <tr> 
     <td><%= @posts.title %></td> 
     <td><%= @posts.text %></td> 
     </tr> 
     <% end %> 
    </tr> 
    </table> 

當我試圖在本地主機上 訪問得到這個錯誤 在帖子#指數

+0

請顯示您的config/routes.rb –

回答

1

轉換NoMethodError此

<% @posts.each do |posts| %> 
    <tr> 
    <td><%= @posts.title %></td> 
    <td><%= @posts.text %></td> 
    </tr> 
    <% end %> 

t這

<% @posts.each do |posts| %> 
    <tr> 
    <td><%= posts.title %></td> 
    <td><%= posts.text %></td> 
    </tr> 
    <% end %> 
+0

哦,該死!我沒有注意到! tsk我的壞我把$ posts.title謝謝你的幫助! –

+0

不要忘記接受答案,以便別人可以找到你的問題解決了 – Jeet

+1

好的,必須等5分鐘才能接受答案 –

相關問題