在Ruby Rails应用程序中,我收到"project/app/controllers/workouts_controller.rb:43:语法错误,意外keyword_end,期望$end



所以我一直在查看堆栈溢出,试图找到我遇到解析错误的原因。这是一个相对较新的 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关键字的原因

相关内容

最新更新