开发者

"Module is not missing constant Model" - Rails 3 error

开发者 https://www.devze.com 2023-03-06 08:46 出处:网络
I have namespaced my models and controllers within my app. when I try to visit admin/stories.html (NameSpace::Admin::StoriesController)

I have namespaced my models and controllers within my app.

when I try to visit admin/stories.html (NameSpace::Admin::StoriesController)

I keep getting an error "NameSpace is not missing constant Story!"

here's a copy of my controller for refe开发者_Python百科rence:

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

I'm using Rails 3.1.0.beta1 with REE


Using module instead of the colon notation for the class name to indicate namespacing fixed the issue for me in Rails 3.0.15

e.g.

module Foo
  class Bar
  ...
  end
end

vs

class Foo::Bar
end


This was a Rails error

Fixed by updating to the latest version of Rails 3.1.0.beta1 on Rails/Master @ github.

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

then

bundle install
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号