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

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

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

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

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

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

Q&A

解決済

1回答

811閲覧

Errno::ENOENT in Shops#index No such file or directory というエラーが発生してしまいました。

Tonny_engineer

総合スコア1

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

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

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

0グッド

0クリップ

投稿2021/03/27 11:30

編集2021/03/27 13:06

Errno::ENOENT in Shops#index No such file or directory というエラーが発生してしまいました。

activeHashを用いて都道府県、エリア、ジャンルをプルダウンで選択し、それぞれのidとレコードの数に+1することでそのレコード専用のIDを作成しようとしたところ

Errno::ENOENT in Shops#index No such file or directory

というエラーが出てしまいました

理想は以下のコードを使ってIDを作成することで
例) 東京都のエリア5の飲食店 -> 21361
のようなIDを作成したいです。

prefecture.rb

class Prefecture < ActiveHash::Base self.data = [ { id: 1, name: '---', pref_id:'00'}, { id: 2, name: '北海道', pref_id: '01'}, { id: 3, name: '青森県', pref_id: '02'}, { id: 4, name: '岩手県', pref_id: '03'}, { id: 5, name: '宮城県', pref_id: '04'}, { id: 6, name: '秋田県', pref_id: '05'}, { id: 7, name: '山形県', pref_id: '06'}, { id: 8, name: '福島県', pref_id: '07'}, { id: 9, name: '茨城県', pref_id: '08'}, { id: 10, name: '栃木県', pref_id: '09'}, { id: 11, name: '群馬県', pref_id: '10'}, { id: 12, name: '埼玉県', pref_id: '11'}, { id: 13, name: '千葉県', pref_id: '12'}, { id: 14, name: '東京都', pref_id: '13'}, { id: 15, name: '神奈川県', pref_id: '14'}, { id: 16, name: '新潟県', pref_id: '15'}, { id: 17, name: '富山県', pref_id: '16'}, { id: 18, name: '石川県', pref_id: '17'}, { id: 19, name: '福井県', pref_id: '18'}, { id: 20, name: '山梨県', pref_id: '19'}, { id: 21, name: '長野県', pref_id: '20'}, { id: 22, name: '岐阜県', pref_id: '21'}, { id: 23, name: '静岡県', pref_id: '22'}, { id: 24, name: '愛知県', pref_id: '23'}, { id: 25, name: '三重県', pref_id: '24'}, { id: 26, name: '滋賀県', pref_id: '25'}, { id: 27, name: '京都府', pref_id: '26'}, { id: 28, name: '大阪府', pref_id: '27'}, { id: 29, name: '兵庫県', pref_id: '28'}, { id: 30, name: '奈良県', pref_id: '29'}, { id: 31, name: '和歌山県', pref_id: '30'}, { id: 32, name: '鳥取県', pref_id: '31'}, { id: 33, name: '島根県', pref_id: '32'}, { id: 34, name: '岡山県', pref_id: '33'}, { id: 35, name: '広島県', pref_id: '34'}, { id: 36, name: '山口県', pref_id: '35'}, { id: 37, name: '徳島県', pref_id: '36'}, { id: 38, name: '香川県', pref_id: '37'}, { id: 39, name: '愛媛県', pref_id: '38'}, { id: 40, name: '高知県', pref_id: '39'}, { id: 41, name: '福岡県', pref_id: '40'}, { id: 43, name: '佐賀県', pref_id: '41'}, { id: 42, name: '長崎県', pref_id: '42'}, { id: 44, name: '熊本県', pref_id: '43'}, { id: 45, name: '大分県', pref_id: '44'}, { id: 46, name: '宮崎県', pref_id: '45'}, { id: 47, name: '鹿児島県', pref_id: '46'}, { id: 48, name: '沖縄県', pref_id: '47'}, { id: 49, name: 'オンライン', pref_id: '48'} ] include ActiveHash::Associations has_many :shops end

genre.rb

class

1 self.data = [ 2 { id: 1, genre: '---' }, 3 { id: 2, genre: '飲食'}, 4 { id: 3, genre: 'ファッション'}, 5 { id: 4, genre: '娯楽'}, 6 { id: 5, genre: 'サロン・美容'}, 7 { id: 6, genre: '旅行・レジャー'}, 8 { id: 7, genre: '電化製品'}, 9 { id: 8, genre: 'スポーツ'}, 10 { id: 9, genre: '本・電子書籍'}, 11 { id: 10, genre: '音楽'}, 12 { id: 11, genre: '車・バイク'}, 13 { id: 12, genre: 'インテリア'}, 14 { id: 13, genre: '日用雑貨'}, 15 { id: 14, genre: 'サービス・リフォーム'}, 16 { id: 15, genre: '金融'}, 17 { id: 16, genre: 'ニュース'}, 18 { id: 17, genre: '教育'}, 19 { id: 18, genre: 'その他'}, 20 ] 21 include ActiveHash::Associations 22 has_many :shops 23end

area.rb

class Area < ActiveHash::Base self.data = [ { id: 1, area_code: '---' }, { id: 2, area_code: 'エリア1'}, { id: 3, area_code: 'エリア2'}, { id: 4, area_code: 'エリア3'}, { id: 5, area_code: 'エリア4'}, { id: 6, area_code: 'エリア5'}, { id: 7, area_code: 'エリア6'}, { id: 8, area_code: 'エリア7'}, { id: 9, area_code: 'エリア8'}, { id: 10, area_code: 'エリア9'}, { id: 11, area_code: 'エリア10'}, ] include ActiveHash::Associations has_many :shops end

index.html.erb

<h1>店舗一覧</h1> </div> <div class = 'go_generate'> <div class = 'btn'> <%= link_to '新規IDを生成する', new_shop_path, class: 'generate_btn'%> </div> <div class = 'shops_index'> <% @shops.each do |shop|%> <div class = "shop_list"> <span>店舗一覧</span> <div class = 'shop_info'> <h3 class = 'shop_name'><%= shop.shop_name%></h3> <h3 class = 'shop_genre'><%= shop.genre.genre%></h3> <h3 class = 'shop_number'><%= `#{shop.genre.id}#{shop.prefecture.pref_id}#{shop.area.id}#{shop.id}`%></h3> </div> </div> <% end %> </div>

shops_controller.rb

class ShopsController < ApplicationController def index @shops = Shop.all end def new @shop = Shop.new end def create @shop = Shop.new(shop_params) if @shop.save redirect_to root_path else redirect_to :index end end private def shop_params params.require(:shop).permit(:shop_name, :genre_id, :prefecture_id, :area_id, :shop_number) end end

追記

エラーメッセージをほぼ完コピしました。

Errno::ENOENT in Shops#index Showing /Users/tomohirotakahashi/Dropbox/id_generator/app/views/shops/index.html.erb where line #20 raised: No such file or directory - 913101 Extracted source (around line #20): 18   <h3 class = 'shop_name'><%= shop.shop_name%></h3> 19   <h3 class = 'shop_genre'><%= shop.genre.genre%></h3> 20 <h3 class = 'shop_number'><%= `#{shop.genre.id}#{shop.prefecture.pref_id}#{shop.area.id}#{shop.id}`%></h3> 21 22 </div> 23 </div> Rails.root: /Users/ユーザー名(個人情報のため隠しています)/Dropbox/id_generator

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

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

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

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

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

winterboum

2021/03/27 11:53

どんな名前の というのがありませんでした? エラーメッセージは全文載せましょう
Tonny_engineer

2021/03/27 13:02 編集

すみません。 ``` Errno::ENOENT in Shops#index Showing /Users/tomohirotakahashi/Dropbox/id_generator/app/views/shops/index.html.erb where line #20 raised: No such file or directory - 913101 Extracted source (around line #20): 18   <h3 class = 'shop_name'><%= shop.shop_name%></h3> 19   <h3 class = 'shop_genre'><%= shop.genre.genre%></h3> 20 <h3 class = 'shop_number'><%= `#{shop.genre.id}#{shop.prefecture.pref_id}#{shop.area.id}#{shop.id}`%></h3> 21 22 </div> 23 </div> Rails.root: /Users/ユーザー名(個人情報のため隠しています)/Dropbox/id_generator ``` ほぼこれで完全コピペです。どうでしょうか。
winterboum

2021/03/27 13:32 編集

はいこれくらい載せてください。 で、 これ質問を編集してそちらに移してください。他の方の目に触れやすいように。 で、 みたところ fileもdirもアクセスしていないようなので??です あ、もうえらー 載ってますね
guest

回答1

0

ベストアンサー

これかな。。。。
<%= #{shop.genre.id}#{shop.prefecture.pref_id}#{shop.area.id}#{shop.id}%>

の <%= %> の内側が 半角の逆クオーテーション で囲まれてますね。
なのでそういう unix コマンドの実行 になってます。
ダブルコーテーションで囲んでください

投稿2021/03/27 13:38

winterboum

総合スコア23505

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

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

Tonny_engineer

2021/03/27 13:39

解消できました!!ありがとうございます!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.39%

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

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

質問する

関連した質問