質問編集履歴

1

文章の変更。

2021/04/24 10:43

投稿

Marchan4
Marchan4

スコア15

test CHANGED
@@ -1 +1 @@
1
- rails s コマンドを入力してhttp://localhost:3000にアクセスしたらTypeErrorが出たため、ハッシュか文字列書き換える方法を教えてください。
1
+ rails :ブラウザにアクセスしたらTypeErrorが出たため、相手に自分のパスワードが知れないよう自分のmysqlのrootパスワードを設定して、データベースを作成する方法を教えてください。
test CHANGED
@@ -34,186 +34,118 @@
34
34
 
35
35
  該当する27行目のソースコードを
36
36
 
37
- Hash(ハッシュ)からString(文字列)に書換えいということを意味してることが分かるのですが
37
+ Hash(ハッシュ)からString(文字列)への暗黙の変換はできないということが分かったため``config/database.yml``ファイルに
38
+
39
+
40
+
41
+ ```
42
+
43
+ password: <%= ENV['RAILS_DATABASE_PASSWORD'] %>
44
+
45
+ ```
38
46
 
39
47
 
40
48
 
41
49
 
42
50
 
43
- 27行目の
51
+ と設定致した後に、ターミナルに
52
+
53
+
44
54
 
45
55
  ```
46
56
 
57
+ $ vim .bash_profile
58
+
59
+ ```
60
+
61
+ と打ち込んで、enterキーを押して画面が切り替わったら、iキーを押してインサートモードにて
62
+
63
+
64
+
65
+ ```
66
+
47
- err.instance_variable_set('@sql_state', sql_state.respond_to?(:encode) ? sql_state.encode(ENCODE_OPTS) : sql_state)
67
+ export RAILS_DATABASE_PASSWORD='自分のMySQLのrootパスワード'
68
+
69
+ ```
70
+
71
+ を入力し、escキーを押してインサートモードを終了させて、「:wq」と入力して保存して終了させて、ターミナルに
72
+
73
+
74
+
75
+ ```
76
+
77
+ $ source ~/.bash_profile
48
78
 
49
79
  ```
50
80
 
51
81
 
52
82
 
83
+ と入力致しました。その後に、ターミナルに
84
+
85
+
86
+
87
+ ```
88
+
89
+ $ rails db:create
90
+
91
+ ```
92
+
93
+ と入力致したところ、
94
+
95
+
96
+
97
+ 下記のエラーが出ました。
98
+
99
+
100
+
101
+ ```
102
+
103
+ $ rails db:create
104
+
105
+
106
+
107
+ no implicit conversion of Hash into String
108
+
109
+ Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/tmp/mysql.sock", "database"=>"tasklist
110
+
111
+ _development"}
112
+
113
+ rails aborted!
114
+
115
+ TypeError: no implicit conversion of Hash into String
116
+
117
+ ```
118
+
119
+
120
+
121
+ ここで二点質問なのですが、
122
+
123
+
124
+
125
+ まず、相手に自分のmysqlのrootパスワードを知られないように自分のmysqlのrootパスワードを設定して、データベース(``tasklist_development``、``tasklist_test``)を作成する方法を教えていただいてもよろしいでしょうか。
126
+
127
+
128
+
129
+ 最後に、もしもこのデータベース(``tasklist_development``、``tasklist_test``)が作成されたら、
130
+
131
+
132
+
133
+ ```
134
+
53
- のどこをHash(ハッシュ)からStringに書き換えるのかを具体的に教えていただけますでしょうか。
135
+ TypeError no implicit conversion of Hash into String
136
+
137
+ ```
138
+
139
+
140
+
141
+ というエラーを解決できて、
142
+
143
+
144
+
145
+ rails s コマンドを入力してhttp://localhost:3000にアクセスして、ブラウザ上で以下の画像が表示されるのでしょうか。
54
146
 
55
147
 
56
148
 
57
149
 
58
150
 
59
-
60
-
61
-
62
-
63
- ``vendor/bundle/ruby/3.0.0/gems/mysql2-0.4.10/lib/mysql2/error.rb``は以下の通りです。
64
-
65
- 先程の該当する27行目のソースコードがこのerror.rbファイルの27行目にあります。
66
-
67
-
68
-
69
- ```
70
-
71
-
72
-
73
- # encoding: UTF-8
74
-
75
-
76
-
77
- module Mysql2
78
-
79
- class Error < StandardError
80
-
81
- ENCODE_OPTS = {
82
-
83
- :undef => :replace,
84
-
85
- :invalid => :replace,
86
-
87
- :replace => '?'.freeze,
88
-
89
- }.freeze
90
-
91
-
92
-
93
- attr_reader :error_number, :sql_state
94
-
95
-
96
-
97
- # Mysql gem compatibility
98
-
99
- alias_method :errno, :error_number
100
-
101
- alias_method :error, :message
102
-
103
-
104
-
105
- def initialize(msg)
106
-
107
- @server_version ||= nil
108
-
109
-
110
-
111
- super(clean_message(msg))
112
-
113
- end
114
-
115
-
116
-
117
- def self.new_with_args(msg, server_version, error_number, sql_state)
118
-
119
- err = allocate
120
-
121
- err.instance_variable_set('@server_version', server_version)
122
-
123
- err.instance_variable_set('@error_number', error_number)
124
-
125
- err.instance_variable_set('@sql_state', sql_state.respond_to?(:encode) ? sql_state.encode(ENCODE_OPTS) : sql_state)
126
-
127
- err.send(:initialize, msg)
128
-
129
- err
130
-
131
- end
132
-
133
-
134
-
135
- private
136
-
137
-
138
-
139
- # In MySQL 5.5+ error messages are always constructed server-side as UTF-8
140
-
141
- # then returned in the encoding set by the `character_set_results` system
142
-
143
- # variable.
144
-
145
- #
146
-
147
- # See http://dev.mysql.com/doc/refman/5.5/en/charset-errors.html for
148
-
149
- # more context.
150
-
151
- #
152
-
153
- # Before MySQL 5.5 error message template strings are in whatever encoding
154
-
155
- # is associated with the error message language.
151
+ ![イメージ説明](4d7e323edd307e21215572bd318b06a2.png)
156
-
157
- # See http://dev.mysql.com/doc/refman/5.1/en/error-message-language.html
158
-
159
- # for more information.
160
-
161
- #
162
-
163
- # The issue is that the user-data inserted in the message could potentially
164
-
165
- # be in any encoding MySQL supports and is insert into the latin1, euckr or
166
-
167
- # koi8r string raw. Meaning there's a high probability the string will be
168
-
169
- # corrupt encoding-wise.
170
-
171
- #
172
-
173
- # See http://dev.mysql.com/doc/refman/5.1/en/charset-errors.html for
174
-
175
- # more information.
176
-
177
- #
178
-
179
- # So in an attempt to make sure the error message string is always in a valid
180
-
181
- # encoding, we'll assume UTF-8 and clean the string of anything that's not a
182
-
183
- # valid UTF-8 character.
184
-
185
- #
186
-
187
- # Except for if we're on 1.8, where we'll do nothing ;)
188
-
189
- #
190
-
191
- # Returns a valid UTF-8 string in Ruby 1.9+, the original string on Ruby 1.8
192
-
193
- def clean_message(message)
194
-
195
- return message unless message.respond_to?(:encode)
196
-
197
-
198
-
199
- if @server_version && @server_version > 50500
200
-
201
- message.encode(ENCODE_OPTS)
202
-
203
- else
204
-
205
- message.encode(Encoding::UTF_8, ENCODE_OPTS)
206
-
207
- end
208
-
209
- end
210
-
211
- end
212
-
213
- end
214
-
215
-
216
-
217
-
218
-
219
- ```