質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

1回答

1154閲覧

ECサイト作成中 rails にてLoadError

fishmilk0313

総合スコア2

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/08/18 11:43

railsでECサイトを作っていて管理画面から見れる会員一覧ページを製作中です
contorollerでいろいろ定義したのですが、どうやらそれを持ってこれてないみたいで解決方法が分かる方、アドバイスお願いします。
LoadErroor
Unable to autoload constant CustomersController, expected /home/vagrant/work/vagrant/nagano-cake/app/controllers/customers_controller.rb to define it
が出てきてます

hostcustomercontoroller

1class Hosts::CustomersController < ApplicationController 2 def index 3 @customers = Customers.all 4 end 5 6 def show 7 @customer =Customers.find(params[:id]) 8 end 9 10 def edit 11 @customer = Customers.find(params[:id]) 12 end 13 14 def update 15 @customer =Customer.find(params[:id]) 16 if @customer.update(params_customer) 17 redirect_to host_customer_path(@customer) 18 else 19 render 'edit' 20 end 21 end 22 23 private 24 def params_customer 25 params.require(:customer).permit( 26 :family_name, 27 :first_name, 28 :family_name_kana, 29 :first_name_kana, 30 :postal_code, 31 :address, 32 :phone_number, 33 :email, 34 ) 35 end 36 37 38end 39

index

1<div class="container"> 2 <div class="row"> 3 <h3 class="login-title col-xs-offset-2">会員一覧</h3> 4 <table class="table table-bordered"> 5 <thead> 6 <th>会員ID</th> 7 <th>氏名</th> 8 <th>メールアドレス</th> 9 <th>ステータス</th> 10 </thead> 11 <tbody> 12 <%= @customers.each do |customer| %> 13 <tr> 14 <td><%= customer.id %></td> 15 <td> 16 <%= link_to hosts_customer_path(customer) do %> 17 <%= customer.family_name%><%= customer.first_name %> 18 </td> 19 <td><%= customer.email %></td> 20 <td> 21 <% if customer.is_deleted ==true %> 22 有効 23 <% else %> 24 退会済み 25 <% end %> 26 </td> 27 </tr> 28 <% end %> 29 </tbody> 30 </table> 31 </div> 32 </div>

hostmodel

1class Host < ApplicationRecord 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :validatable 6end 7

schema

1# This file is auto-generated from the current state of the database. Instead 2# of editing this file, please use the migrations feature of Active Record to 3# incrementally modify your database, and then regenerate this schema definition. 4# 5# Note that this schema.rb definition is the authoritative source for your 6# database schema. If you need to create the application database on another 7# system, you should be using db:schema:load, not running all the migrations 8# from scratch. The latter is a flawed and unsustainable approach (the more migrations 9# you'll amass, the slower it'll run and the greater likelihood for issues). 10# 11# It's strongly recommended that you check this file into your version control system. 12 13ActiveRecord::Schema.define(version: 2020_08_18_044619) do 14 15 create_table "customers", force: :cascade do |t| 16 t.string "email", default: "", null: false 17 t.string "encrypted_password", default: "", null: false 18 t.string "reset_password_token" 19 t.datetime "reset_password_sent_at" 20 t.datetime "remember_created_at" 21 t.datetime "created_at", null: false 22 t.datetime "updated_at", null: false 23 t.string "family_name", null: false 24 t.string "first_name", null: false 25 t.string "family_name_kana", null: false 26 t.string "first_name_kana", null: false 27 t.string "postal_code", null: false 28 t.string "address", null: false 29 t.string "phone_number", null: false 30 t.boolean "is_deleted", default: false, null: false 31 t.index ["email"], name: "index_customers_on_email", unique: true 32 t.index ["reset_password_token"], name: "index_customers_on_reset_password_token", unique: true 33 end 34 35 create_table "hosts", force: :cascade do |t| 36 t.string "email", default: "", null: false 37 t.string "encrypted_password", default: "", null: false 38 t.string "reset_password_token" 39 t.datetime "reset_password_sent_at" 40 t.datetime "remember_created_at" 41 t.index ["email"], name: "index_hosts_on_email", unique: true 42 t.index ["reset_password_token"], name: "index_hosts_on_reset_password_token", unique: true 43 end 44 45 create_table "items", force: :cascade do |t| 46 t.integer "genre_id" 47 t.string "name" 48 t.text "description" 49 t.integer "non_tax_price" 50 t.string "image_id" 51 t.boolean "is_active" 52 t.datetime "created_at", null: false 53 t.datetime "updated_at", null: false 54 end 55 56end 57

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

Unable to autoload constant CustomersController,
つまり CustomersController が欲しいのに定義されているのは
class Hosts::CustomersController

なのでそうなります。
app/controllers/customers_controller.rb
に定義するなら Hosts:: なしの CustomersController でなければなりません。
rails では class名とそれを定義するfile名は(あるルール下で)一致している必要があります

投稿2020/08/18 22:23

winterboum

総合スコア23329

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問