質問編集履歴
1
コントローラーとビューのコードを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,8 +13,87 @@
|
|
13
13
|
12:
|
14
14
|
|
15
15
|
app/views/coffees/show.html.erb:9
|
16
|
+
|
16
17
|
```
|
18
|
+
<h1>Coffee詳細</h1>
|
19
|
+
<div class="coffee">
|
20
|
+
<p><%= @coffee.name %></p>
|
21
|
+
<p><%= @coffee.created_at %></p>
|
22
|
+
<p><%= image_tag @coffee.image_url, size: "250x200" if @coffee.image? %></p>
|
17
23
|
|
24
|
+
</div>
|
25
|
+
<h1>users#show</h1>
|
26
|
+
<p>名前 : <%= @user.name %></p>
|
27
|
+
<p>メールアドレス : <%= @user.email %></p>
|
28
|
+
<p>プロフィール : <%= @user.profile %></p>
|
29
|
+
|
30
|
+
<% if current_user.id == @user.id %>
|
31
|
+
<%= link_to "編集する", edit_user_registration_path %>
|
32
|
+
<% end %>
|
33
|
+
|
34
|
+
<h2>ユーザーの投稿一覧</h2>
|
35
|
+
<% @user.coffees.each do |t| %>
|
36
|
+
<%= t.user.name %>
|
37
|
+
<%= t.body %>
|
38
|
+
<% end %>
|
39
|
+
<%= link_to "編集する", edit_coffee_path(@coffee.id) %>
|
40
|
+
<%= link_to "Coffee一覧に戻る", coffees_path %>
|
41
|
+
|
42
|
+
class CoffeesController < ApplicationController
|
43
|
+
before_action :authenticate_user!, only: [:new, :create]
|
44
|
+
def index
|
45
|
+
@coffees=Coffee.all
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def new
|
50
|
+
@coffee = Coffee.new
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def create
|
55
|
+
coffee = Coffee.new(coffee_params)
|
56
|
+
coffee.user_id = current_user.id
|
57
|
+
if coffee.save
|
58
|
+
redirect_to :action => "index"
|
59
|
+
else
|
60
|
+
redirect_to :action => "new"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def show
|
65
|
+
@coffee = Coffee.find(params[:id])
|
66
|
+
end
|
67
|
+
|
68
|
+
def edit
|
69
|
+
@coffee =Coffee.find(params[:id])
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def update
|
74
|
+
coffee = Coffee.find(params[:id])
|
75
|
+
if coffee.update(coffee_params)
|
76
|
+
redirect_to :action => "show", :id => coffee.id
|
77
|
+
else
|
78
|
+
redirect_to :action => "new"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def destroy
|
84
|
+
coffee = Coffee.find(params[:id])
|
85
|
+
coffee.destroy
|
86
|
+
redirect_to action: :index
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
def coffee_params
|
91
|
+
params.require(:coffee).permit(:name, :address, :telephone, :seat, :wifi, :smoke, :image)
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
end
|
96
|
+
|
18
97
|
ActiveRecord::Schema.define(version: 2021_09_27_150000) do
|
19
98
|
|
20
99
|
create_table "coffees", force: :cascade do |t|
|