未定义的局部变量或方法`post'for#<postscontroller:0x007f76b8ee5be8>

时间:2017-06-20 06:21:05

标签: ruby-on-rails

我收到此错误,但我已经在控制器中定义了我的方法,我是ruby的新手,我该怎么办帮助我,我的错误来自@post未定义的控制器

这是我的控制器

class PostsController < ApplicationController 

     def index
        @posts = post.all    
      end

      def show

      end

      def new

      end

      def create

      end

      def edit

      end

      def update

      end

      def destroy

      end

    end

这是我的观点

<h1>regular</h1>

<% @posts.each do |post| %>
<h2> <%= post.username  %></h2>
<p><%= post.description  %></p>
<% end %>

这是我的迁移

class CreatePosts < ActiveRecord::Migration
  def up
    create_table :posts do |t|
      t.string :username
      t.text :description

      t.timestamps
    end
  end
  def down
    drop_table :posts
  end
end

这是我的路线

Rails.application.routes.draw do
  resources :posts

1 个答案:

答案 0 :(得分:0)

你必须使用大写P.

目前,您的代码会在控制器操作中搜索名为from typing import NamedTuple Point = NamedTuple('Point', [('x', int), ('y', int)]) def add(self: Point, other: Point) -> Point: return Point(self.x + other.x, self.y + other.y) Point.__add__ = add a = Point(1, 2) b = Point(3, 4) print(a + b) # prints 'Point(4, 6)' 的本地变量或实例方法。

要调用课程,您必须使用post