[Rails] syntax error, unexpected tSTRING_END, expecting'''

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

If you write code like the above, syntax error, unexpected tSTRING_END, expecting ' ' Came out. Did you forget to add "" or "in the string? I thought, but there seems to be no problem.

It took a lot of time, but it was resolved. An error occurred because there was a space between% w

seed.rb


#%Error because there was a half-width space after w
given_names = %w {
Jiro:Jiro:jiro
Saburo:Sabrow:saburo
Matsuko:Matsuko:matsuko
Takeko:Takeko:takeko
Umeko:Umeko:umeko
}

Fix this and solve

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

Notice with syntax highlighting! I felt it, but I didn't understand.

If you insert a space in Ruby's% notation, an error will occur like this. It was today's learning.

Recommended Posts

[Rails] syntax error, unexpected tSTRING_END, expecting'''
[Rails error] unexpected tIDENTIFIER
[Rails] Unexpected validation error in devise
[Review] When creating a web application with Rails, syntax error, unexpected')', expecting => ...]}% ","% # {params [: content]}% "]) ...
[Rails] How to solve "Uglifier :: Error: Unexpected character'`'"
[Note] Rails error list
Catch Rails Routing Error
Mac Rails Install Error
rails heroku error log
rails error resolution summary
rails error Library not loaded
Error in rails db: migrate
[Rails] Rails version upgrade error memorandum
Error when using rails capybara
[rails] error during devise installation
syntax error [each do end error]
[Rails] About Uglifier :: Error: Unexpected token: at the time of deployment