2017-04-13 2 views
0

カスタムフォトモデルをスプリーストアの管理パネルに追加しようとしていますが、ページに移動するときにエラーが発生します。私はファイル名の付け方や配置場所と関係があると感じています。これは私がこれまで持っているものです。spreeにカスタムモデルを追加してエラーを取得する:初期化されていない定数Admin

ルート

namespace :admin do 
    resources :photos 
end 

マイビューファイルは、すべての場所にあります。アプリ/ビュー/酒宴/管理/写真

アプリ/コントローラ/管理/ photos_controller.rbここで

module Admin 
    class PhotosController < Admin::BaseController 
     before_action :set_photo, only: [:show, :edit, :update, :destroy] 

    # GET /photos 
    # GET /photos.json 
    def index 
    @photos = Photo.all 
    end 

    # GET /photos/1 
    # GET /photos/1.json 
    def show 
    end 

    # GET /photos/new 
    def new 
    @photo = Photo.new 
    end 

    # GET /photos/1/edit 
    def edit 
    end 

    # POST /photos 
    # POST /photos.json 
    def create 
    @photo = Photo.new(photo_params) 

    respond_to do |format| 
     if @photo.save 
     format.html { redirect_to @photo, notice: 'Photo was successfully created.' } 
     format.json { render :show, status: :created, location: @photo } 
     else 
     format.html { render :new } 
     format.json { render json: @photo.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # PATCH/PUT /photos/1 
    # PATCH/PUT /photos/1.json 
    def update 
    respond_to do |format| 
     if @photo.update(photo_params) 
     format.html { redirect_to @photo, notice: 'Photo was successfully updated.' } 
     format.json { render :show, status: :ok, location: @photo } 
     else 
     format.html { render :edit } 
     format.json { render json: @photo.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # DELETE /photos/1 
    # DELETE /photos/1.json 
    def destroy 
    @photo.destroy 
    respond_to do |format| 
     format.html { redirect_to photos_url, notice: 'Photo was successfully destroyed.' } 
     format.json { head :no_content } 
    end 
    end 

    private 
    # Use callbacks to share common setup or constraints between actions. 
    def set_photo 
     @photo = Photo.find(params[:id]) 
    end 

    # Never trust parameters from the scary internet, only allow the white list through. 
    def photo_params 
     params.require(:photo).permit(:image, :book_id) 
    end 





    end 
    end 

は完全なエラーです:

Started GET "/admin/photos" for 207.93.212.56 at 2017-04-13 19:18:41 +0000 
Cannot render console from 207.93.212.56! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 

ActionController::RoutingError (uninitialized constant Admin): 
    activesupport (4.2.6) lib/active_support/inflector/methods.rb:261:in `const_get' 
    activesupport (4.2.6) lib/active_support/inflector/methods.rb:261:in `block in constantize' 
    activesupport (4.2.6) lib/active_support/inflector/methods.rb:259:in `each' 
    activesupport (4.2.6) lib/active_support/inflector/methods.rb:259:in `inject' 
    activesupport (4.2.6) lib/active_support/inflector/methods.rb:259:in `constantize' 
    actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:70:in `controller_reference' 
    actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:60:in `controller' 
    actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:39:in `serve' 
    actionpack (4.2.6) lib/action_dispatch/journey/router.rb:43:in `block in serve' 
    actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in `each' 
    actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in `serve' 
    actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:817:in `call' 
    warden (1.2.7) lib/warden/manager.rb:36:in `block in call' 
    warden (1.2.7) lib/warden/manager.rb:35:in `catch' 
    warden (1.2.7) lib/warden/manager.rb:35:in `call' 
    rack (1.6.5) lib/rack/etag.rb:24:in `call' 
    rack (1.6.5) lib/rack/conditionalget.rb:25:in `call' 
    rack (1.6.5) lib/rack/head.rb:13:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/flash.rb:260:in `call' 
    rack (1.6.5) lib/rack/session/abstract/id.rb:225:in `context' 
    rack (1.6.5) lib/rack/session/abstract/id.rb:220:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/cookies.rb:560:in `call' 
    activerecord (4.2.6) lib/active_record/query_cache.rb:36:in `call' 
    activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call' 
    activerecord (4.2.6) lib/active_record/migration.rb:377:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
    activesupport (4.2.6) lib/active_support/callbacks.rb:88:in `__run_callbacks__' 
    activesupport (4.2.6) lib/active_support/callbacks.rb:778:in `_run_call_callbacks' 
    activesupport (4.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/reloader.rb:73:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call' 
    web-console (2.3.0) lib/web_console/middleware.rb:20:in `block in call' 
    web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch' 
    web-console (2.3.0) lib/web_console/middleware.rb:18:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
    railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app' 
    railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call' 
    activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
    activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged' 
    activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged' 
    railties (4.2.6) lib/rails/rack/logger.rb:20:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
    rack (1.6.5) lib/rack/methodoverride.rb:22:in `call' 
    rack (1.6.5) lib/rack/runtime.rb:18:in `call' 
    activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
    rack (1.6.5) lib/rack/lock.rb:17:in `call' 
    actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call' 
    rack (1.6.5) lib/rack/sendfile.rb:113:in `call' 
    railties (4.2.6) lib/rails/engine.rb:518:in `call' 
    railties (4.2.6) lib/rails/application.rb:165:in `call' 
    rack (1.6.5) lib/rack/lock.rb:17:in `call' 
    rack (1.6.5) lib/rack/content_length.rb:15:in `call' 
    rack (1.6.5) lib/rack/handler/webrick.rb:88:in `service' 
    /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service' 
    /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run' 
    /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread' 
+0

エラーの詳細な説明は何ですか。 –

+0

@alejandroMontilla最新のエラー – Kris

+0

でポストを更新しました。フォトコントローラの問題のようです。名前とパスを確認してください( 'app/controllers/admin/photos_controller.rb'のようにする必要があります) –

答えて

0

は、あなたが使用する必要があります。

class PhotosController < BaseController 

をあなたはadmin名前空間すでに

1

まあ内部にあるので、あなたはあなたを助ける適切なモジュールscoping.Thisコードスニペットを使用する必要があります。

module Spree 
    module Admin 
    class PhotosController < BaseController 
     before_action :set_photo, only: [:show, :edit, :update, :destroy] 

     # GET /photos 
     # GET /photos.json 
     def index 
     @photos = Photo.all 
     end 

     # GET /photos/1 
     # GET /photos/1.json 
     def show 
     end 

     # GET /photos/new 
     def new 
     @photo = Photo.new 
     end 

     # GET /photos/1/edit 
     def edit 
     end 

     # POST /photos 
     # POST /photos.json 
     def create 
     @photo = Photo.new(photo_params) 

     respond_to do |format| 
      if @photo.save 
      format.html { redirect_to @photo, notice: 'Photo was successfully created.' } 
      format.json { render :show, status: :created, location: @photo } 
      else 
      format.html { render :new } 
      format.json { render json: @photo.errors, status: :unprocessable_entity } 
      end 
     end 
     end 

     # PATCH/PUT /photos/1 
     # PATCH/PUT /photos/1.json 
     def update 
     respond_to do |format| 
      if @photo.update(photo_params) 
      format.html { redirect_to @photo, notice: 'Photo was successfully updated.' } 
      format.json { render :show, status: :ok, location: @photo } 
      else 
      format.html { render :edit } 
      format.json { render json: @photo.errors, status: :unprocessable_entity } 
      end 
     end 
     end 

     # DELETE /photos/1 
     # DELETE /photos/1.json 
     def destroy 
     @photo.destroy 
     respond_to do |format| 
      format.html { redirect_to photos_url, notice: 'Photo was successfully destroyed.' } 
      format.json { head :no_content } 
     end 
     end 

     private 
     # Use callbacks to share common setup or constraints between actions. 
     def set_photo 
      @photo = Photo.find(params[:id]) 
     end 

     # Never trust parameters from the scary internet, only allow the white list through. 
     def photo_params 
      params.require(:photo).permit(:image, :book_id) 
     end 

     end 
    end 
    end 
end 

また、私はResourceController代わりのBaseControllerからクラスを継承するために、あなたをお勧めします。そうすることで、いくつかのLOCを節約することができ、本当に役に立ちます。

関連する問題