【问题标题】:"Module is not missing constant Model" - Rails 3 error“模块不缺少常量模型”-Rails 3 错误
【发布时间】:2011-05-17 17:30:04
【问题描述】:

我已经在我的应用程序中命名了我的模型和控制器。

当我尝试访问 admin/stories.html (NameSpace::Admin::StoriesController)

我不断收到错误消息“NameSpace is not missing constant Story!”

这是我的控制器的副本供参考:

class NameSpace::Admin::StoriesController < NameSpace::ApplicationController

  layout "admin"
  before_filter :admin_login_required

  cache_sweeper NameSpace::StorySweeper, :only => [:update,:destroy]

  # expose is provided by the DecentExposure Gem
  expose(:stories) { current_place.stories.where(:state => %w{ submitted published }).order("created_at DESC").page(params[:page]).per(25) }
  expose(:story)

  def create
    if params[:success] == "1"
      Story.find_or_create_by_media_id(params[:media_id])      
      redirect_to admin_stories_url, :notice => "Successfully created story! It should appear here in a few minuntes once it's been processed."
    else
      flash.now[:error] = "There was an error when creating your story!<br>If this happens again, please contact support@#{APP_CONFIG[:domain]}".html_safe
      render :new
    end
  end

  def index
  end

  def show
  end

  def new
  end

  def edit
  end

  def update
    if story.update_attributes(params[:story])
      redirect_to admin_stories_url, :notice => "Successfully updated story."
    else
      render :action => 'edit'
    end
  end

  def destroy
    story.remove!
    redirect_to admin_stories_url, :notice => "Story successfully destroyed!"
  end

end

我正在使用带有 REE 的 Rails 3.1.0.beta1

【问题讨论】:

    标签: ruby-on-rails-3 namespaces


    【解决方案1】:

    使用module 代替冒号表示类名来指示命名空间解决了我在 Rails 3.0.15 中的问题

    例如

    module Foo
      class Bar
      ...
      end
    end
    

    class Foo::Bar
    end
    

    【讨论】:

      【解决方案2】:

      这是一个 Rails 错误

      通过在 Rails/Master @ github 上更新到最新版本的 Rails 3.1.0.beta1 修复。

      # Gemfile
      gem "rails", :git => "git://github.com/rails/rails.git"  
      

      然后

      bundle install
      

      【讨论】:

      • 呸,一些关于具体错误或原因的信息对将来的参考很有用(得到这个是Rails 2.3.11)
      • 同意——你能补充一些关于你是如何追踪这个问题的信息吗?谢谢!
      • 对不起,伙计们——我确定这是对 github 问题之一的评论——可能来自 JoshPeek,建议升级到最前沿。该解决方案对我有用,所以我没有深入挖掘。祝你好运
      • 为那些停留在旧版本(我是 3.0.11)的人提供解决方案
      猜你喜欢
      • 1970-01-01
      • 2018-04-03
      • 2015-09-08
      • 2011-12-25
      • 2020-01-30
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      相关资源
      最近更新 更多