加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – “模块不缺少常量模型” – Rails 3错误

发布时间:2020-12-17 01:59:14 所属栏目:百科 来源:网络整理
导读:我在我的应用程序中命名了我的模型和控制器. 当我尝试访问admin / stories.html(NameSpace :: Admin :: StoriesController)时 我一直收到错误“NameSpace不会错过常数故事
我在我的应用程序中命名了我的模型和控制器.

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

我一直收到错误“NameSpace不会错过常数故事!”

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

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

我正在使用Rails 3.1.0.beta1和REE

解决方法

使用模块而不是类名的冒号表示来指示命名空间在Rails 3.0.15中修复了我的问题

例如

module Foo
  class Bar
  ...
  end
end

VS

class Foo::Bar
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读