質問編集履歴
1
文章の変更。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
rails
|
1
|
+
rails :ブラウザにアクセスしたらTypeErrorが出たため、相手に自分のパスワードが知られないように自分のmysqlのrootパスワードを設定して、データベースを作成する方法を教えてください。
|
body
CHANGED
@@ -16,95 +16,61 @@
|
|
16
16
|
というエラー内容から、
|
17
17
|
|
18
18
|
該当する27行目のソースコードを
|
19
|
-
Hash(ハッシュ)からString(文字列)
|
19
|
+
Hash(ハッシュ)からString(文字列)への暗黙の変換はできないということが分かったため、``config/database.yml``ファイルに
|
20
20
|
|
21
|
-
|
22
|
-
27行目の
|
23
21
|
```
|
24
|
-
|
22
|
+
password: <%= ENV['RAILS_DATABASE_PASSWORD'] %>
|
25
23
|
```
|
26
24
|
|
27
|
-
のどこをHash(ハッシュ)からStringに書き換えるのかを具体的に教えていただけますでしょうか。
|
28
25
|
|
26
|
+
と設定致した後に、ターミナルに
|
29
27
|
|
28
|
+
```
|
29
|
+
$ vim .bash_profile
|
30
|
+
```
|
31
|
+
と打ち込んで、enterキーを押して画面が切り替わったら、iキーを押してインサートモードにて
|
30
32
|
|
33
|
+
```
|
34
|
+
export RAILS_DATABASE_PASSWORD='自分のMySQLのrootパスワード'
|
35
|
+
```
|
36
|
+
を入力し、escキーを押してインサートモードを終了させて、「:wq」と入力して保存して終了させて、ターミナルに
|
31
37
|
|
32
|
-
``
|
38
|
+
```
|
33
|
-
|
39
|
+
$ source ~/.bash_profile
|
40
|
+
```
|
34
41
|
|
42
|
+
と入力致しました。その後に、ターミナルに
|
43
|
+
|
35
44
|
```
|
45
|
+
$ rails db:create
|
46
|
+
```
|
47
|
+
と入力致したところ、
|
36
48
|
|
37
|
-
|
49
|
+
下記のエラーが出ました。
|
38
50
|
|
39
|
-
|
51
|
+
```
|
40
|
-
class Error < StandardError
|
41
|
-
ENCODE_OPTS = {
|
42
|
-
:undef => :replace,
|
43
|
-
|
52
|
+
$ rails db:create
|
44
|
-
:replace => '?'.freeze,
|
45
|
-
}.freeze
|
46
53
|
|
47
|
-
|
54
|
+
no implicit conversion of Hash into String
|
55
|
+
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/tmp/mysql.sock", "database"=>"tasklist
|
56
|
+
_development"}
|
57
|
+
rails aborted!
|
58
|
+
TypeError: no implicit conversion of Hash into String
|
59
|
+
```
|
48
60
|
|
49
|
-
|
61
|
+
ここで二点質問なのですが、
|
50
|
-
alias_method :errno, :error_number
|
51
|
-
alias_method :error, :message
|
52
62
|
|
53
|
-
def initialize(msg)
|
54
|
-
|
63
|
+
まず、相手に自分のmysqlのrootパスワードを知られないように自分のmysqlのrootパスワードを設定して、データベース(``tasklist_development``、``tasklist_test``)を作成する方法を教えていただいてもよろしいでしょうか。
|
55
64
|
|
56
|
-
|
65
|
+
最後に、もしもこのデータベース(``tasklist_development``、``tasklist_test``)が作成されたら、
|
57
|
-
end
|
58
66
|
|
67
|
+
```
|
59
|
-
|
68
|
+
TypeError no implicit conversion of Hash into String
|
60
|
-
err = allocate
|
61
|
-
err.instance_variable_set('@server_version', server_version)
|
62
|
-
err.instance_variable_set('@error_number', error_number)
|
63
|
-
err.instance_variable_set('@sql_state', sql_state.respond_to?(:encode) ? sql_state.encode(ENCODE_OPTS) : sql_state)
|
64
|
-
err.send(:initialize, msg)
|
65
|
-
|
69
|
+
```
|
66
|
-
end
|
67
70
|
|
68
|
-
|
71
|
+
というエラーを解決できて、
|
69
72
|
|
70
|
-
# In MySQL 5.5+ error messages are always constructed server-side as UTF-8
|
71
|
-
# then returned in the encoding set by the `character_set_results` system
|
72
|
-
# variable.
|
73
|
-
#
|
74
|
-
# See http://dev.mysql.com/doc/refman/5.5/en/charset-errors.html for
|
75
|
-
# more context.
|
76
|
-
#
|
77
|
-
# Before MySQL 5.5 error message template strings are in whatever encoding
|
78
|
-
# is associated with the error message language.
|
79
|
-
# See http://dev.mysql.com/doc/refman/5.1/en/error-message-language.html
|
80
|
-
# for more information.
|
81
|
-
#
|
82
|
-
# The issue is that the user-data inserted in the message could potentially
|
83
|
-
# be in any encoding MySQL supports and is insert into the latin1, euckr or
|
84
|
-
|
73
|
+
rails s コマンドを入力してhttp://localhost:3000にアクセスして、ブラウザ上で以下の画像が表示されるのでしょうか。
|
85
|
-
# corrupt encoding-wise.
|
86
|
-
#
|
87
|
-
# See http://dev.mysql.com/doc/refman/5.1/en/charset-errors.html for
|
88
|
-
# more information.
|
89
|
-
#
|
90
|
-
# So in an attempt to make sure the error message string is always in a valid
|
91
|
-
# encoding, we'll assume UTF-8 and clean the string of anything that's not a
|
92
|
-
# valid UTF-8 character.
|
93
|
-
#
|
94
|
-
# Except for if we're on 1.8, where we'll do nothing ;)
|
95
|
-
#
|
96
|
-
# Returns a valid UTF-8 string in Ruby 1.9+, the original string on Ruby 1.8
|
97
|
-
def clean_message(message)
|
98
|
-
return message unless message.respond_to?(:encode)
|
99
74
|
|
100
|
-
if @server_version && @server_version > 50500
|
101
|
-
message.encode(ENCODE_OPTS)
|
102
|
-
else
|
103
|
-
message.encode(Encoding::UTF_8, ENCODE_OPTS)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
75
|
|
109
|
-
|
110
|
-
|
76
|
+

|