syntax error, unexpected tSTRING_END, expecting ' '
seed.rb
StaffMember.create!(
email: "[email protected]",
family_name: "Yamada",
given_name: "Taro",
family_name_kana: "Yamada",
given_name_kana: "Taro",
password: "password",
start_date: Date.today
)
family_names = %w {
Sato:Sato:sato
Suzuki:Suzuki:suzuki
Takahashi:Takahashi:takahashi
Tanaka:Tanaka:tanaka
}
given_names = %w {
Jiro:Jiro:jiro
Saburo:Sabrow:saburo
Matsuko:Matsuko:matsuko
Takeko:Takeko:takeko
Umeko:Umeko:umeko
}
20.times do |n|
fn = family_names[n%4].split(":")
gn = given_names[n%5].split(":")
StaffMember.create!(
email: "#{fn[2]}.#{gn[2]}@example.com",
family_name: fn[0],
given_name: gn[0],
family_name_kana: fn[1],
given_name_kana: gn[1],
password: "password",
start_date: (100-n).days.ago.to_date,
end_date: n == 0 ? Date.today : nil,
suspended: n == 1
)
end
Si vous écrivez du code comme ci-dessus, syntax error, unexpected tSTRING_END, expecting ' ' Sortit de. Avez-vous oublié d'ajouter "" ou "dans la chaîne? J'ai pensé, mais il ne semble y avoir aucun problème.
Cela a pris beaucoup de temps, mais cela a été résolu. Une erreur s'est produite car il y avait un espace entre% w
seed.rb
#%Erreur car il y avait un espace demi-largeur après w
given_names = %w {
Jiro:Jiro:jiro
Saburo:Sabrow:saburo
Matsuko:Matsuko:matsuko
Takeko:Takeko:takeko
Umeko:Umeko:umeko
}
Corrigez cela et résolvez
seed.rb
StaffMember.create!(
email: "[email protected]",
family_name: "Yamada",
given_name: "Taro",
family_name_kana: "Yamada",
given_name_kana: "Taro",
password: "password",
start_date: Date.today
)
family_names = %w{
Sato:Sato:sato
Suzuki:Suzuki:suzuki
Takahashi:Takahashi:takahashi
Tanaka:Tanaka:tanaka
}
given_names = %w{
Jiro:Jiro:jiro
Saburo:Sabrow:saburo
Matsuko:Matsuko:matsuko
Takeko:Takeko:takeko
Umeko:Umeko:umeko
}
20.times do |n|
fn = family_names[n%4].split(":")
gn = given_names[n%5].split(":")
StaffMember.create!(
email: "#{fn[2]}.#{gn[2]}@example.com",
family_name: fn[0],
given_name: gn[0],
family_name_kana: fn[1],
given_name_kana: gn[1],
password: "password",
start_date: (100-n).days.ago.to_date,
end_date: n == 0 ? Date.today : nil,
suspended: n == 1
)
end
Avis avec des points forts de la syntaxe! Je l'ai senti, mais je n'ai pas compris.
Si vous insérez un espace dans la notation% de Ruby, une erreur se produira comme ceci. C'était l'apprentissage d'aujourd'hui.
Recommended Posts