Nameerror in Postscontroller#index | uninitialized Constant Postscontroller::Post

Asked

Viewed 468 times

0

inserir a descrição da imagem aqui

Guys, accidentally my girlfriend went through the folders of my project in Ruby on Rails and started giving this error. What can I do? He doesn’t seem to recognize the Post as a class...

2 answers

0

Check if the class Post is correctly defined in the file app/models/post.rb of your application’s file system and whether it is implemented similar to:

class Post
  # código
end

Accidents do happen. One advice I give you is to convert your application code with a version control system, like Git (https://git-scm.com/). This way, any accidental change or loss of code can be easily reversed.

0

You didn’t import your Post model into the Controller, so it can’t identify the class.

class PostController < ApplicationController
  require 'models/post'

  def index
    @posts = Post.All
  end
end

Browser other questions tagged

You are not signed in. Login or sign up in order to post.