teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

書式の訂正

2020/11/07 13:46

投稿

gannbaritai
gannbaritai

スコア2

title CHANGED
File without changes
body CHANGED
@@ -1,16 +1,12 @@
1
1
  ### 前提・実現したいこと
2
- プログラミング学習中の初学者です。
3
- 質問の仕方や常識の足りないところありましたら、ご指摘お願いします。
4
-
5
2
  内容は、トップページに投稿した内容の一覧を表示したいのですが、エラーが解除できずに困っています。
6
3
  エラーを解除して投稿一覧をトップページに表示したいです。
4
+
7
5
  railsのバージョンは『Rails 6.0.3.4』です。
8
6
 
9
- 前提として、画像の扱いとしてはImageMagickを使っています。
7
+ 画像の扱いとしてはImageMagickを使っています。
10
8
  表示したい内容のデータはデータベースに保存されていることを確認しました。
11
-
12
- ここに質問の内容を詳しく書いてください。
9
+ ###質問の内容
13
-
14
10
  Ruby on Railsでアプリを作成しております。
15
11
  トップページに投稿の一覧を表示する機能を実装中にエラーになりました。
16
12
  まず、投稿したものの一覧を表示したいのですが、
@@ -119,7 +115,10 @@
119
115
  end
120
116
  end
121
117
  ```
122
- ###
118
+ ###後書き
119
+ プログラミング学習中の初学者です。
120
+ 質問の仕方や常識の足りないところありましたら、ご指摘お願いします。
121
+
123
- 簡単なことでしたら申し訳ないです。
122
+ エラーの質問内容に関しまして簡単なことでしたら申し訳ないです。
124
123
  ですが、長いこと調べても解決ができませんでした。
125
124
  どうすれば表示ができるのかアドバイスをお願いいたします。

1

書き方の修正

2020/11/07 13:46

投稿

gannbaritai
gannbaritai

スコア2

title CHANGED
File without changes
body CHANGED
@@ -19,16 +19,106 @@
19
19
  エラー文を調べてみたのですがいくら考えても自分では解決ができませんでした。
20
20
 
21
21
  ### 発生している問題・エラーメッセージ
22
+ ```
23
+ Sprockets::Rails::Helper::AssetNotFound in Prototypes#index
24
+ Showing /Users/etsuya/projects/protospace-31640/app/views/prototypes/_prototype.html.erb where line #2 raised:
25
+
22
- ![エラーの内容](49b4b2ab853931b816d3aedee9235389.png)
26
+ The asset "" is not present in the asset pipeline.
27
+ ```
23
28
  ### 該当のソースコード
29
+ routes.rb
30
+ ```
31
+ Rails.application.routes.draw do
32
+ devise_for :users
33
+ root to: "prototypes#index"
24
- ![routes.rb](5cc9075f374ed86dc5ca53541f4af700.png)
34
+ resources :prototypes, only: [:index, :new, :create]
35
+ end
36
+ ```
25
- ![prototype.rb](6fc1ccf0d670c3b7a8af5d7e9b2d7893.png)
37
+ prototypes_controller.rb
38
+ ```
26
- ![prototypes_controller.rb](c9c764f77fa4c1ed6030f3bdf58a96a6.png)
39
+ class PrototypesController < ApplicationController
27
- ![index.html.erb](402370193ed44a3d50a0b42946fb4dd1.png)
40
+ def index
28
- ![_prototype.html.erb](173b91a97555f0d98017c958416f22d3.png)
41
+ @prototypes = Prototype.all
29
- ![DB_create_prototypes.rb](05fae10d8a14f0a51673c6cad246d354.png)
42
+ end
30
43
 
44
+ def new
45
+ @prototype = Prototype.new
46
+ end
31
47
 
48
+ def create
49
+ @prototype = Prototype.new(prototype_params)
50
+
51
+ if @prototype.save
52
+ redirect_to root_path
53
+ else
54
+ render :new
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def prototype_params
61
+ params.require(:prototype).permit(:title, :catch_copy, :concept, :image).merge(user_id: current_user.id)
62
+ end
63
+
64
+ end
65
+ ```
66
+ prototype.rb
67
+ ```
68
+ class Prototype < ApplicationRecord
69
+ has_many :comments
70
+ belongs_to :user
71
+ has_one_attached :image
72
+
73
+ validates :title, presence: true
74
+ validates :catch_copy, presence: true
75
+ validates :concept, presence: true
76
+ validates :image, presence: true
77
+ end
78
+ ```
79
+ index.html.erb
80
+ ```
81
+ <main class="main">
82
+ <div class="inner">
83
+ <% if user_signed_in? %>
84
+ <div class="greeting">
85
+ <%= "こんにちは" %>
86
+ <%= link_to current_user.name, root_path, class: :greeting__link%>
87
+ </div>
88
+ <% end %>
89
+ <div class="card__wrapper">
90
+ <%= render partial: 'prototype', collection: @prototypes %>
91
+ </div>
92
+ </div>
93
+ </main>
94
+ ```
95
+ _prototype.html.erb
96
+ ```
97
+ <div class="card">
98
+ <%= link_to image_tag("#{prototype.image}", class: :card__img ), root_path%>
99
+ <div class="card__body">
100
+ <%= link_to "#{prototype.title}", root_path, class: :card__title%>
101
+ <p class="card__summary">
102
+ <%= "#{prototype.catch_copy}" %>
103
+ </p>
104
+ <%= link_to "by #{prototype.user.name}", root_path, class: :card__user %>
105
+ </div>
106
+ </div>
107
+ ```
108
+ 20XXXX_create_prototypes.rb
109
+ ```
110
+ class CreatePrototypes < ActiveRecord::Migration[6.0]
111
+ def change
112
+ create_table :prototypes do |t|
113
+ t.string :title, null: false, default:""
114
+ t.text :catch_copy
115
+ t.text :concept
116
+ t.references :user, foreign_key: true
117
+ t.timestamps
118
+ end
119
+ end
120
+ end
121
+ ```
32
122
  ###
33
123
  簡単なことでしたら申し訳ないです。
34
124
  ですが、長いこと調べても解決ができませんでした。