简体   繁体   中英

undefined method `action' for ArticlesController(Table doesn't exist):Class - Ruby on Rails error

I got an error notification but I dont know where to search. See attachement.

Where's the file with the included error? I did the following instruction: http://guides.rubyonrails.org/getting_started.html

Here's my code:

class ArticlesController < ActiveRecord::Base
  def index
    @articles = Article.all
  end

  def show
    @article = Article.find(params[:id])
  end

  def new
    @article = Article.new
  end

  def edit
    @article = Article.find(params[:id])
  end

  def create
    @article = Article.new(article_params)

    if @article.save
      redirect_to @article
    else
      render 'new'
    end
  end

  def update
    @article = Article.find(params[:id])

    if @article.update(article_params)
      redirect_to @article
    else
      render 'edit'
    end
  end

  def destroy
    @article = Article.find(params[:id])
    @article.destroy

    redirect_to articles_path
  end

  private #description
    def article_params #description
      params.require(:article).permit(:title, :text)
    end #here's the end
end

在此输入图像描述

Change

class ArticlesController < ActiveRecord::Base
// ...
end

to

class ArticlesController < ApplicationController
// ...
end

ActiveRecord::Base is for models.

why the controller inherits ActiveRecord ?

try changing ArticlesController < ActiveRecord::Base to ArticlesController < ApplicationController

If application_controller.rb is not present in your project, then create one with the following code.

class ApplicationController < ActionController::Base

end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM