ruby-on-rails – 类CommentController(TypeError)的超类不匹配,重命名的最佳方法是什么?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 类CommentController(TypeError)的超类不匹配,重命名的最佳方法是什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
今晚我在部署时遇到了一些问题,我正试图尽快解决这个问题

我不知道为什么会这样.一切都在本地很好,但不是在heroku上.我在研究之后尝试了各种不同的修复方法,但我可能不得不完全重命名这个类的CommentsController(希望这很有效).最好的方法是什么?我对Rails很新,所以我需要一些帮助才能正确地改变它们.

以下是CommentsController看起来像FYI的内容

class CommentsController < ApplicationController
  def new
    @post = Post.new(params[:post])
  end

  def show
    @comment = Comment.find(params[:id])
    respond_to do |format|
      format.js
    end
  end

  def create
    @post = Post.find(params[:post_id])
    @comment = Comment.new(params[:comment])
    @comment.micropost = @post
    @comment.user = current_user
    if @comment.save
      redirect_to(:back)
    else
      render partial: 'shared/_comment_form',locals: { post: @post }
    end
  end
end

评论与每个帖子相关联(用户可以对帖子发表评论).如果需要,我也会发布其他代码.

这是heroku日志的错误

2013-04-09T05:55:19.454545+00:00 app[web.2]: /app/app/controllers/comments_contr
oller.rb:1:in `<top (required)>': superclass mismatch for class CommentsControll
er (TypeError)

Routes.db

SampleApp::Application.routes.draw do
  resources :posts,:path => "posts"

  resources :users do
    resources :messages do
      collection do
        post :delete_selected
      end
    end
  end

  ActiveAdmin.routes(self)

  devise_for :admin_users,ActiveAdmin::Devise.config

  resources :users do
    member do
      get :following,:followers
    end
  end

  resources :sessions,only: [:new,:create,:destroy]
  resources :posts,only: [:create,:destroy]
  resources :relationships,:destroy]
  resources :posts do
    resources :comments
  end

  root to: 'static_pages#home'

  match '/signup',to: 'users#new'
  match '/signin',to: 'sessions#new'
  match '/signout',to: 'sessions#destroy',via: :delete

  match '/post',to: 'static_pages#post'
  match '/post1',to: 'static_pages#post1'
  match '/faq',to: 'static_pages#faq'
  match '/review',to: 'users#review'
  match "/posts/:id/review" => "posts#review"
end

当我在rails app文件夹中运行高级索引搜索时,会出现相关文件

- comments_controller.rb
- comments_helper.rb
- comments_helper_spec.rb
- comments_controller_spec.rb
- 3 migration files
- routes.rb (posted above)
- schema.rb (table called "active_admin_comments" and table called "comments')
- post.rb model (has_many :comments)
- user.rb model (has_many :comments)
- comment.rb model
- active_admin.rb in config/initializer (any instance where I find "comments" has been #'ed out")

解决方法

我有几乎相同的问题(服务器启动正确,但rspec失败,同样的错误).
在我的情况下,问题出在ActiveAdmin(0.6.0)中.不知道到底是什么,也许是命名空间中的东西.

刚刚降级到0.5.0在该版本上,CommentsController没有问题.

原文链接:https://www.f2er.com/ruby/270674.html

猜你在找的Ruby相关文章