类CommentsController(TypeError)的超类不匹配,重命名的最佳方法是什么? [英] superclass mismatch for class CommentsController (TypeError), best way to rename?

查看:156
本文介绍了类CommentsController(TypeError)的超类不匹配,重命名的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今晚部署时遇到了一些问题,我试图尽快解决此问题

I ran into some problem tonight while deploying and I'm trying to get this fixed asap

我不知道为什么会这样.在本地一切正常,但在heroku上则不行.在研究之后,我尝试了各种不同的修复程序,但我可能不得不诉诸完全重命名此类CommentsController(希望它能起作用).最好的方法是什么?我是Rails的新手,所以我需要一些帮助来正确更改这些内容.

I have no idea why this is happening. Everything works fine locally but not on heroku. I tried all sorts of different fixes after researching but I may have to resort to renaming this class CommentsController completely (hopefully that works). What is the best way to go about that? I'm pretty new to Rails so I need some help on making these changing correctly.

这是CommentController的样子,仅供参考:

Here's what the CommentsController looks like 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

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

Comments are associated to each post (users are able to comment on posts). I will post other codes up as well if needed.

这是heroku日志中的错误

Here's the error from heroku logs

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

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, only: [:create, :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应用程序文件夹中运行高级索引搜索时,这是出现的相关文件

When I ran advanced indexed search inside the rails app folder, here were the relevant files that came up

- 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)中.不知道到底是什么,也许与命名空间有关.

I had almost the same issue (server starts correctly, but RSpec fails with the same error). In my case, the problem was in ActiveAdmin (0.6.0). Don't know what exactly, maybe something related to namespacing.

仅降级至0.5.0 在那个版本上,我对CommentsController没有任何问题.

Just downgraded to 0.5.0 On that version, I didn't have any problems with CommentsController.

这篇关于类CommentsController(TypeError)的超类不匹配,重命名的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆