uninitialized constant TimelistsController:: Become Timelist

Asked 2 years ago, Updated 2 years ago, 46 views

When I looked it up online, it said that the cause was a mismatch between the file name and the class name, but the file name is timelists_controller.rb and the code matches the class name as follows:Please tell me how to resolve it.

class TimelistsController<ApplicationController
  before_action —require_user_logged_in
  def index
    @timelists=Timelist.all
  end
  def create
    @timelist=Timelist.new(time_params)
    [email protected]
      flash.now [:success] = "Posted."
      render "toppages/index"
    else
      
      flash.now [:danger] = "Post failed."
      render "toppages/index"
    end
  end
  
  def destroy
    @timelist=Timelist.find (params[:id])
    @timelist.destroy
    
    flash.now [:success] = "Your behavior has been logged."
    render "times.index"
  end
  
  def time_params
    param.require(:timemanagement).permit(:content)
  end
end

ruby-on-rails ruby

2022-09-30 14:20

1 Answers

The method in the TimelistsController class references Timelist, but because it is not defined anywhere, it is uninitialized constant.

If Timelist is defined under the TimelistsController or is defined at the top level, no error occurs.


2022-09-30 14:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.