获取语​​法错误,意外的keyword_end,期望输入结束

时间:2014-08-13 16:46:22

标签: ruby ruby-on-rails-4

这工作到5分钟前,我不确定我编辑的内容是什么搞砸了。我已回滚到之前的版本,我仍然收到错误。我一行一行地确保没有额外的结束,除非我是盲人,否则每个end都与def匹配。

特定错误: SyntaxError in CompaniesController#index /projects/TSO/app/controllers/companies_controller.rb:93: syntax error, unexpected keyword_end, expecting end-of-input

这是我的代码:

    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

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

1 个答案:

答案 0 :(得分:2)

你的缩进搞砸了,因为它,你已经在那里添加了额外的end

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