ArticlesController中的SyntaxError

时间:2016-05-16 22:48:04

标签: ruby-on-rails

我在使用此代码时遇到了一些麻烦。其实很简单,但我找不到问题。该页面正在运行,但现在我得到了这个错误。我即将在heroku上部署它。我刚刚完成了ruby上的销毁部分

and/home/nitrous/code/rails_projects/alpha-blog/app/controllers/articles_controller.rb:2: syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '(' before_action :set_article, only:[:edit, :update,:show,:destroy] ^.here's my code

class ArticlesController < ApplicationController>
before_action :set_article, only:[:edit, :update,:show,:destroy]


 def new
 @article =Article.new
 end

  def edit
  end

def create
   @article =Article.new(article_params)
   if@article.save
     flash[:notice] = "Article was successfully created"
   redirect_to article_path(@article)
     else
     render 'new'
   end
   end

 def update
      if@article.update
        flash[:notice] = "Article was successfully updated"
        redirect_to article_path(@article)
    else
    render 'edit'
 end
end

def show
end


def destroy
 @article.destroy
 flash[:notice]= "Article was successfully deleted"
 redirect_to_articles_path
end

private
  def set_article
    @article = Article.find(params[:id])
  end
def article_params
  params.require(:article).permit(:title, :description)
end
end

1 个答案:

答案 0 :(得分:1)

在ApplicationController

之后删除>
class ArticlesController < ApplicationController