Ruby 获取语法错误,意外的关键字\u end,应为输入结尾

Ruby 获取语法错误,意外的关键字\u end,应为输入结尾,ruby,ruby-on-rails-4,Ruby,Ruby On Rails 4,这是工作,直到5分钟前,我不知道我编辑了什么,把事情搞砸了。我已经回滚到以前的版本,但仍然会出现错误。我一行一行地检查以确保没有多余的端点,除非我是盲人,否则每个端点都与def匹配 具体错误: CompanyController#索引中的语法错误 /projects/TSO/app/controllers/companys\u controller.rb:93:语法错误,意外的关键字\u end,预期输入结束 这是我的密码: class CompaniesController <

这是工作,直到5分钟前,我不知道我编辑了什么,把事情搞砸了。我已经回滚到以前的版本,但仍然会出现错误。我一行一行地检查以确保没有多余的端点,除非我是盲人,否则每个
端点都与
def
匹配

具体错误: CompanyController#索引中的语法错误 /projects/TSO/app/controllers/companys\u controller.rb:93:语法错误,意外的关键字\u end,预期输入结束

这是我的密码:

    class CompaniesController < ApplicationController
  before_action :set_company, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_contact!, only: [:index, :show, :edit, :update, :destroy]


  # GET /companies
  # GET /companies.json
  def index
   @company = Company.find(@company.id, include: :contacts, include: :subscriptions)
  end

  # GET /companies/1
  # GET /companies/1.json
  def show

    @company = Company.find(@company.id, include: :contacts, include: :subscriptions)

  end

  # GET /companies/new
  def new
    @company = Company.new
    @company.contacts.build

  end

  # GET /companies/1/edit
  def edit
  end

  # POST /companies
  # POST /companies.json
  def create
    @company = Company.new(company_params)


    respond_to do |format|
      if @company.save
         sign_in(@company.contacts.first)

        format.html { redirect_to @company, notice: 'Company was successfully created.' }
        format.json { render action: 'show', status: :created, location: @company }
      else
        format.html { render action: 'new' }
        format.json { render json: @company.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /companies/1
  # PATCH/PUT /companies/1.json
  def update
    respond_to do |format|
      if @company.update(company_params)
        format.html { redirect_to @company, notice: 'Company was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @company.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /companies/1
  # DELETE /companies/1.json
  def destroy
    @company.destroy
    respond_to do |format|
      format.html { redirect_to companies_url }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_company
      if params[:id].nil?
        @company = Company.find(current_contact.company_id)
      else
        @company = Company.find(params[:id])
      end
    end


    # Never trust parameters from the scary internet, only allow the white list through.
    def company_params
      params.require(:company).permit(:name, :legal_entity, :KVK_number, :VAT_number, contacts_attributes:[:first_name, :last_name, :address, :phone, :email, :postcode, :password] )
    end
  end
end
class CompaniesController

不知道我现在做错了什么。

你的缩进搞砸了,因此你在缩进中添加了一个额外的
结尾

private
声明应与
class
处于同一级别

常规模板如下所示:

class Example
  def method
    # ...
  end

private
  def private_method
  end
end
你所拥有的:

class Example
  def method
    # ...
  end

  private
    def private_method
    end
  end
end

谢谢-这是问题的一部分,但我发现真正的根本原因是在subscription.rb模型中,我添加了一个新方法,但最终弄糟了。为了解决这个问题,我删除了控制器中的额外端,然后在调用订阅模型时出现了下一个端错误。因此,公司控制器中需要订阅模型的任何内容都会导致错误。在修复模型后,所有工作正常