簡體   English   中英

在Ruby Rails應用中,我得到“ project / app / controllers / workouts_controller.rb:43:語法錯誤,意外的keyword_end,期望$ end

[英]In a Ruby Rails App, I am getting "project/app/controllers/workouts_controller.rb:43: syntax error, unexpected keyword_end, expecting $end

因此,我一直在研究Stack Overflow,以尋找導致出現解析錯誤的原因。 這是一個相對較新的Rails應用程序,但我認為我可以成功在Heroku上進行部署,所以我不會錯過任何配置。

從以前的Stackoverflow帖子看來,我似乎還有一個額外的結尾,因為Rails抱怨在期望文件結尾時發現結尾。 我嘗試取出最后一個端點(對於控制器類本身來說更接近),並注釋掉代碼的各個部分,但根本不起作用。 是否有人對如何規避/解決此問題有任何想法/建議?

這是我的控制器文件

Class WorkoutsController < ApplicationController

  def show
    id = params[:id] # retrieve workout ID from URI route
    @workout = Workout.find(id) # look up workout by unique ID
    # will render app/views/workouts/show.<extension> by default
  end

  def index
    @all_workouts = Workout.all_workouts
    @workouts = Workout.all
  end

  def new
    # default: render 'new' template
  end

  def create
    @workout = Workout.create!(params[:workout])
    flash[:notice] = "#{@workout.title} was successfully created."
    redirect_to workouts_path
  end

  def edit
    @workout = Workout.find params[:id]
  end

  def update
    @workout = Workout.find params[:id]
    @workout.update_attributes!(params[:workout])
    flash[:notice] = "#{@workout.title} was successfully updated."
    redirect_to workouts_path(@workout)
  end

  def destroy
    @workout = Workout.find(params[:id])
    @workout.destroy
    flash[:notice] = "Workout '#{@workout.title}' destroyed."
    redirect_to workouts_path
  end


end

可能不需要這樣做,但這是我的模型文件:

Class Workout < ActiveRecord::Base

  attr_accessible :title, :time, :creator, :exercise_list

  def self.all_exercises
    %w(push-ups pull-ups crunches rest)
  end
end

更換

Class WorkoutsController < ApplicationController

class WorkoutsController < ApplicationController

與您的模型相同。 class關鍵字應在低位寄存器中使用。 我假設您打印錯了字,這就是為什么解析器看到多余的end關鍵字

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM