TutorsController 中的 NoMethodError#create undefined method `supert=' for #<Tutor:0x00007fa5593f99f8> 你是说吗?超级=超级超级超级?

NoMethodError in TutorsController#create undefined method `supert=' for #<Tutor:0x00007fa5593f99f8> Did you mean? super= super super super?

我一直在尝试向 Rails 应用程序上的 Ruby 添加一个布尔值以进行辅导。我保持 运行 进入以下错误:Error Messsage

NoMethodError in TutorsController#create undefined method `supert=' for #Tutor:0x00007fa5593f99f8 Did you mean? super= super super super?

我采取了与创建变量“academy”相同的步骤,没有出现问题。

tutors_controller.rb

   class TutorsController < ApplicationController
  def new
   @tutor_person = TutorPerson.new
   @person = Person.new
   @tutor = Tutor.new
  end
  
  def edit
     @tutor = Tutor.find(params[:id])
     @person = Person.find(@tutor.people_id)
     @tutor_person = TutorPerson.new({:name => @person.name, :email => @person.email, :grade => @tutor.grade, :id_num => @tutor.id_num})
  end
  
  def show
      unless ((session[:tutor_id].to_s == params[:id]) || (Person.find(session[:tutor_id]).admin))
      
      redirect_to nope_path, :overwrite_params => { :parm => 'foo' }
        return
      end
     @tutor = Tutor.find(params[:id])
     @person = Person.find(@tutor.people_id)
     @tutor_person = TutorPerson.new({:name => @person.name, :email => @person.email, :grade => @tutor.grade, :id_num => @tutor.id_num})
   # debugger
  end
  
  def create
    @checker = false
     @tutor_person = tutor_person
     @person = Person.new
     @tutor = Tutor.new
    Person.all.each do |i|
      if i.email == tutor_params[:email]
        @checker = true
      end
    end
    if !@checker
      @person.email = tutor_params[:email]
      @person.name = tutor_params[:name]
      @person.password = tutor_params[:password]
      @person.password_confirmation = tutor_params[:password_confirmation]
      @tutor = @person.build_tutor
      @tutor.id_num = tutor_params[:id_num]
      @tutor.grade = tutor_params[:grade]
      
      if tutor_params[:academy] == "true"
        @tutor.academy = true
        @person.academy = true
        @tutor.supert = false
        @person.supert = false
      elsif tutor_params[:supert] == "true"
        @tutor.academy = false
        @person.academy = false
        @tutor.supert = true
        @person.supert = true
      else
         @tutor.academy = false
          @person.academy = false
          @tutor.supert = false
          @person.supert = false
      end
        @tutor.adminOverride = tutor_params[:adminKey]
      
          if (@tutor.save && @person.save)
            log_in @person
            @tutor.update_attribute(:adminOverride, nil)
            flash[:success] = "Tutor signup successful!"
            redirect_to controller: "people", action: "show", id: (@tutor.people_id)
          else 
            if @person.errors.any? || @tutor.errors.any?
              render 'new'
            else
              flash[:danger] = "Invalid ID"
              render 'new'
            end
          end
    else
      flash[:danger] = "Email taken"
      render 'new'
    end
    
  end
  
  def update
    @tutor = Person.find(params[:id])
    if @tutor.update_attributes(tutor_params)
      # Handle a successful update.
      
    else
      render 'edit'
    end
  end
  
  def idInvalid
    flash[:danger] = "Invalid ID"
    redirect_to tutorsignup_path
  end
  
  private 
  
    def tutor_params
      params.require(:tutor_person).permit(:id_num, :grade, :name, :email, :password, :password_confirmation, :adminKey, :academy, :supert)
    end
    def tutor_person
      TutorPerson.new(tutor_params)
    end
end

tutor_person.rb

class TutorPerson
    include ActiveModel::Model
    attr_accessor :name, :email, :password, :password_confirmation, :grade, :id_num, :adminKey, :academy, :supert
    
   
    def self.from_tutor_id(id)
        tutor = Tutor.find(id)
        person = Person.find(tutor.people_id)
        new(name: person.name, email: person.email, grade: tutor.grade, id_num: tutor.id_num)
    end
    
    
end

几天来我一直在为这个问题苦苦挣扎,所以任何 tips/pointers 将不胜感激!

谢谢!

编辑:

完整的错误信息如下: errors pt 1 errors pt 2 errors pt 3

actionpack (5.0.7) lib/action_dispatch/middleware/debug_exceptions.rb:53:in `call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.7) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.7) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.7) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.7) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.7) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.7) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.7) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.7) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.7) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.7) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.7) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
railties (5.0.7) lib/rails/engine.rb:522:in `call'
puma (3.9.1) lib/puma/configuration.rb:224:in `call'
puma (3.9.1) lib/puma/server.rb:602:in `handle_request'
puma (3.9.1) lib/puma/server.rb:435:in `process_client'
puma (3.9.1) lib/puma/server.rb:299:in `block in run'
puma (3.9.1) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
  Rendering /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout
  Rendering /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
  Rendered /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (0.8ms)
  Rendered collection of /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/routes/_route.html.erb [91 times] (9.3ms)
  Rendered /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/routes/_table.html.erb (0.7ms)
  Rendering /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
  Rendered /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.6ms)
  Rendered /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (22.9ms)
Started POST "/tutorsignup" for 127.0.0.1 at 2022-01-31 22:14:55 -0800
Processing by TutorsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"HQe62fT7N0MYTr2EFkBBJNevCP8WMRJnVan45yEXyCgm7hmq++uYkrmOo+NS8mQQ8FCCq4u50dO8NdxbwXhfVA==", "tutor_person"=>{"name"=>"asf", "email"=>"asdf@stu.gusd.net", "id_num"=>"123123", "grade"=>"12", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "adminKey"=>"", "academy"=>"false", "supert"=>"true"}, "commit"=>"Create my account"}
  Person Load (0.5ms)  SELECT "people".* FROM "people"
Completed 500 Internal Server Error in 88ms (ActiveRecord: 0.5ms)


  
NoMethodError (undefined method `supert=' for #<Tutor:0x00007fa5593f99f8>
Did you mean?  super=
               super
               super
               super?):
   
app/controllers/tutors_controller.rb:53:in `create'
  Rendering /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
  Rendering /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
  Rendered /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (2.3ms)
  Rendering /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
  Rendered /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)
  Rendering /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
  Rendered /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
  Rendered /Library/Ruby/Gems/2.6.0/gems/actionpack-5.0.7/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (14.2ms)

编辑 2: tutor.rb

class Tutor < ApplicationRecord
     attr_accessor :remember_token, :please
    has_many :subject, foreign_key: :tutor_id, autosave: true, inverse_of: :tutor
    belongs_to :person, foreign_key: :people_id, inverse_of: :tutor
    before_save :save_validation 
    accepts_nested_attributes_for :person
    validates :id_num, presence: true, length: {is: 6}, uniqueness: true, if: :adminOverrideCheck  #, if: :adminOverride
    validates :grade, presence: true
    
    def save_validation
        @check = false
        Cvstudent.all.each do |i|                             #checks that student id exists 
            
            if ((i.idnum == self.id_num))
                @check = true
            end
        end
        
        Person.all.each do |i|                                #if id doesn't exist, check if an admin key was provided (for a new student or someone not in database)
            if (self.adminOverride == i.adminKey)
                @check = true
            end
        end
        if !@check
            puts "EITHER STUDENT ID IS INVALID OR ADMIN KEY IS INVALID (IF IT WAS ENTERED)"
            throw(:abort)
        end
    end
    
    def adminOverrideCheck
        @check = false
        Person.all.each do |i|
            if ((i.admin == true) && (self.adminOverride == i.adminKey))
                @check = true
                return false
            end
        end
        if @check == false
           puts "NO VALID ADMIN KEY ENTERED"
           return true
        end
    end
end

编辑 3:

20220131174537_add_supert_to_tutors.rb

class AddSupertToTutors < ActiveRecord::Migration[5.0]
  def change
    add_column :tutors, :supert, :boolean
  end
end

20220131174630_add_supert_to_people.rb

class AddSupertToPeople < ActiveRecord::Migration[5.0]
  def change
    add_column :people, :supert, :boolean
  end
end

20191002183900_add_academy_to_tutors.rb

class AddAcademyToTutors < ActiveRecord::Migration[5.0]
  def change
    add_column :tutors, :academy, :boolean
  end
end

20191002183929_add_academy_to_people.rb

class AddAcademyToPeople < ActiveRecord::Migration[5.0]
  def change
    add_column :people, :academy, :boolean
  end
end

您似乎希望 Tutor class 具有属性 supert,但 supert 是在 TutorPerson 中定义的,而不是 Tutor.

这就是您获得 NoMethodError 的原因。