質問編集履歴

2

文章追加

2022/01/05 04:41

投稿

tattobu
tattobu

スコア16

test CHANGED
File without changes
test CHANGED
@@ -85,3 +85,75 @@
85
85
  <% end %>
86
86
 
87
87
  ```
88
+
89
+ db/migrate/impressions_table.rb
90
+
91
+ ```ruby
92
+
93
+ class CreateImpressionsTable < ActiveRecord::Migration[6.0]
94
+
95
+ def self.up
96
+
97
+ create_table :impressions, :force => true do |t|
98
+
99
+ t.string :impressionable_type
100
+
101
+ t.integer :impressionable_id
102
+
103
+ t.integer :user_id
104
+
105
+ t.string :controller_name
106
+
107
+ t.string :action_name
108
+
109
+ t.string :view_name
110
+
111
+ t.string :request_hash
112
+
113
+ t.string :ip_address
114
+
115
+ t.string :session_hash
116
+
117
+ t.text :message
118
+
119
+ t.text :referrer
120
+
121
+ t.text :params
122
+
123
+ t.timestamps
124
+
125
+ end
126
+
127
+ add_index :impressions, [:impressionable_type, :message, :impressionable_id], :name => "impressionable_type_message_index", :unique => false, :length => {:message => 191 }
128
+
129
+ add_index :impressions, [:impressionable_type, :impressionable_id, :request_hash], :name => "poly_request_index", :unique => false
130
+
131
+ add_index :impressions, [:impressionable_type, :impressionable_id, :ip_address], :name => "poly_ip_index", :unique => false
132
+
133
+ add_index :impressions, [:impressionable_type, :impressionable_id, :session_hash], :name => "poly_session_index", :unique => false
134
+
135
+ add_index :impressions, [:controller_name,:action_name,:request_hash], :name => "controlleraction_request_index", :unique => false
136
+
137
+ add_index :impressions, [:controller_name,:action_name,:ip_address], :name => "controlleraction_ip_index", :unique => false
138
+
139
+ add_index :impressions, [:controller_name,:action_name,:session_hash], :name => "controlleraction_session_index", :unique => false
140
+
141
+ add_index :impressions, [:impressionable_type, :impressionable_id, :params], :name => "poly_params_request_index", :unique => false, :length => {:params => 191 }
142
+
143
+ add_index :impressions, :user_id
144
+
145
+ end
146
+
147
+
148
+
149
+ def self.down
150
+
151
+ drop_table :impressions
152
+
153
+ end
154
+
155
+ end
156
+
157
+
158
+
159
+ ```

1

分かりやすくコードを短縮

2022/01/05 04:41

投稿

tattobu
tattobu

スコア16

test CHANGED
File without changes
test CHANGED
@@ -34,34 +34,6 @@
34
34
 
35
35
  class ArtistsController < ApplicationController
36
36
 
37
- def show
38
-
39
- @artist = Artist.find(params[:id])
40
-
41
- @songs = @artist.songs.order('id DESC')
42
-
43
- impressionist(@artist, nil, unique: [:session_hash])
44
-
45
- end
46
-
47
-
48
-
49
- def search
50
-
51
- if params[:q]&.dig(:name)
52
-
53
- squished_keywords = params[:q][:name].squish
54
-
55
- params[:q][:name_cont_any] = squished_keywords.split(' ')
56
-
57
- end
58
-
59
- @q = Artist.ransack(params[:q])
60
-
61
- @artists = @q.result
62
-
63
- end
64
-
65
37
 
66
38
 
67
39
  def ranking
@@ -79,18 +51,6 @@
79
51
  view/artists/ranking.html.erb
80
52
 
81
53
  ```ruby
82
-
83
- <%= render "shared/header" %>
84
-
85
- <div class="main">
86
-
87
- <div class="inner">
88
-
89
- <div class="newitem">
90
-
91
- <p>Ranking Artists</p>
92
-
93
- </div>
94
54
 
95
55
  <div class="artist__wrapper">
96
56
 
@@ -124,28 +84,4 @@
124
84
 
125
85
  <% end %>
126
86
 
127
- <%= link_to image_tag(artist.image, class: :card__img ), artist_path(artist.id), method: :get %>
128
-
129
- <div class="card__body">
130
-
131
- <%= link_to artist.name, artist_path(artist.id), class: :card__artist %>
132
-
133
- <%= link_to artist.genre.name, artist_path(artist.id), class: :card__genre %>
134
-
135
- <%= link_to artist.city.name, artist_path(artist.id), class: :card__genre %>
136
-
137
- </div>
138
-
139
- </div>
140
-
141
- <% end %>
142
-
143
- </div>
144
-
145
- </div>
146
-
147
- </div>
148
-
149
- <%= render "shared/footer" %>
150
-
151
87
  ```