gpt4 book ai didi

ruby-on-rails-3 - "Module is not missing constant Model"- Rails 3 错误

转载 作者:行者123 更新时间:2023-12-04 07:04:54 25 4
gpt4 key购买 nike

我在我的应用程序中命名了我的模型和 Controller 。

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

我不断收到错误消息“NameSpace 没有缺少常量 Story!”

这是我的 Controller 的副本以供引用:

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

最佳答案

使用 module而不是类名的冒号表示命名空间在 Rails 3.0.15 中为我解决了这个问题

例如

module Foo
class Bar
...
end
end

对比
class Foo::Bar
end

关于ruby-on-rails-3 - "Module is not missing constant Model"- Rails 3 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6034740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com