Подтвердить что ты не робот

Неверная последовательность байтов в US-ASCII (ошибка аргумента), когда я запускаю rake db: seed in Rails

Когда я запускаю rake db:seed в моем приложении Rails, я получаю эту ошибку:

неверная последовательность байтов в US-ASCII (ошибка аргумента)

Я только что добавил science_majors и вплоть до моего файла семени, и теперь, когда я запускаю rake db:seed, он дает мне эту ошибку:

неверная ошибка последовательности байтов

Почему это и как я могу его исправить?

часть seeds.rb

@college = College.find_or_create_by_name!('University of Pittsburgh')
if @college.update_attributes(
  url: 'university-of-pittsburgh',
  public: 'Public',
  years: '4-year',
  category: 'National University',
  calendar: 'Semester',
  location: 'Pittsburgh, PA',
  setting: 'Large City (250-500k)',
  retention: '90',
  majors: 'business/marketing: 15%|social sciences: 14%|health professions: 11%|english: 10%|engineering: 9%|psychology: 8%|biology: 7%|history: 5%',
  scholarships_link: 'http://www.oafa.pitt.edu/universityschlrs.aspx',
  map: '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=university+of+pittsburgh&amp;aq=&amp;sll=40.444261,-79.970448&amp;sspn=0.142165,0.251656&amp;ie=UTF8&amp;hq=university+of+pittsburgh&amp;t=m&amp;ll=40.443486,-79.958245&amp;spn=0.010798,0.021038&amp;output=embed"></iframe><br /><small><a href="#" onclick="location.href='https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=university+of+pittsburgh&amp;aq=&amp;sll=40.431368,-79.9805&amp;sspn=0.142165,0.251656&amp;ie=UTF8&amp;hq=university+of+pittsburgh&amp;t=m&amp;ll=40.443486,-79.958245&amp;spn=0.010798,0.021038'; return false;" style="color:#0000FF;text-align:left">View Larger Map</a></small>',
  street_view: '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=University+of+Pittsburgh,+4200+Fifth+Ave,+Pittsburgh,+PA&amp;aq=0&amp;oq=uni&amp;sll=40.444261,-79.970448&amp;sspn=0.142165,0.251656&amp;ie=UTF8&amp;hq=University+of+Pittsburgh,+4200+Fifth+Ave,+Pittsburgh,+PA&amp;ll=40.443486,-79.958245&amp;spn=0.010798,0.021038&amp;t=m&amp;layer=c&amp;cbll=40.441775,-79.956671&amp;panoid=BgWQKMiSI1fpwP7JUF16Vg&amp;cbp=12,45.25,,0,-3.34&amp;output=svembed"></iframe><br /><small><a href="#" onclick="location.href='https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=University+of+Pittsburgh,+4200+Fifth+Ave,+Pittsburgh,+PA&amp;aq=0&amp;oq=uni&amp;sll=40.431368,-79.9805&amp;sspn=0.142165,0.251656&amp;ie=UTF8&amp;hq=University+of+Pittsburgh,+4200+Fifth+Ave,+Pittsburgh,+PA&amp;ll=40.443486,-79.958245&amp;spn=0.010798,0.021038&amp;t=m&amp;layer=c&amp;cbll=40.441775,-79.956671&amp;panoid=BgWQKMiSI1fpwP7JUF16Vg&amp;cbp=12,45.25,,0,-3.34'; return false;" style="color:#0000FF;text-align:left">View Larger Map</a></small>',
  housing: '<iframe src="http://www.tour.pitt.edu/tour-categories/residence-halls" scrolling="no" height="820" width="900"></iframe>',
  food: '<div style="overflow: hidden; max-width: 1000px;"><iframe scrolling="no" src="http://www.pc.pitt.edu/dining/menus.php" style="margin-left: 0; height: 2000px; margin-top: -370px; margin-bottom: -375px; width: 750px;"></iframe></div>',
  weather: '<div style="overflow: hidden; max-width: 500px;"><iframe scrolling="no" src="http://www.weather.com/weather/wxclimatology/monthly/graph/USPA1290" style="margin-left: -40px; height: 1570px; margin-top: -490px; width: 500px;"></iframe></div>',
  dorms: 'Towers (fr.)|Sutherland (fr.)|Lothrop (fr.)|Nordenberg (fr.)|Holland (fr.)|Forbes (fr.; honors)|McCormick|Brackenridge|Amos|Bruce|Panther|Pennsylvania|Ruskin|Bouquet Gardens|Oakwood Apartments|Centre-Plaza Apartments|Forbes-Craig Apartments (honors)',
  science_majors: 'Actuarial Mathematics|Applied Mathematics|Bioinformatics|Biological Sciences|Chemistry*|Computer Science|Ecology and Evolution|Environmental Geology|Environmental Studies|Geology|History and Philosophy of Science|Linguistics*|Mathematics*|Mathematics-Economics|Mathematics-Philosophy|Microbiology|Molecular Biology|Natural Sciences Area|Neuroscience*|Physics*|Physics and Astronomy|Scientific Computing|Statistics',
  social_science_majors: 'Economics*|Economics–Statistics|History*|Political Science*|Politics-Philosophy|Psychology|Sociology*|Urban Studies',
  humanities_majors: 'Africana Studies*|Africana Studies–English|Anthropology|Chinese*|Classics*|English Literature*|English Writing|Film Studies*|French*|German|History of Art & Architecture|Humanities Area|Italian*|Italian Studies|Japanese*|Liberal Studies|Music*|Philosophy*|Religious Studies*|Russian|Slavic Studies|Spanish|Studio Arts*|Theatre Arts*',
  business_majors: 'Accounting|Finance|General Management|Global Management|Marketing',
  engineering_majors: 'Bioengineering*|Chemical Engineering*|Civil Engineering*|Computer Engineering|Electrical Engineering*|Engineering Physics|Industrial Engineering*|Materials Science and Engineering*|Mechanical Engineering*',
  professional_majors: 'Administration of Justice*|Applied Developmental Psychology|Architectural Studies|Athletic Training|Clinical Dietetics and Nutrition|Communication: Rhet & Comm|Communication Science|Dental Hygiene|Emergency Medicine|Health Information Management|Health Services|Health and Physical Activity|Information Science|Legal Studies*|Media and Professional Communications|Nursing|Pharmacy|Public Service*|Rehabilitation Science|Social Work*'
)
else
  # handle validation errors
end

@college= College.find_or_create_by_name!('Harvard')
if @college.update_attributes(
  url: 'harvard',
  public: 'Private',
  years: '4-year',
  category: 'National University',
  calendar: 'Semester',
  location: 'Cambridge, MA',
  setting: 'Small City (50-250k)',
  degrees: 'Bachelors, Masters, Doctoral',
  rotc: 'Air Force, Army, Navy',
  considered: 'Academic GPA|Alumni Relation|Application Essay|Character/Personal Qualities|Extracurricular Activities|First Generation College Student|Geographical Residence|Interview|Racial/Ethnic Status|Recommendations|Rigor of secondary school record|Standardized Test Scores|Talent/Ability|Volunteer Work|Work Experience',
  student_faculty: '7 to 1')
else
  # handle validation errors
end

Я оставил все остальные колледжи. До сих пор у меня 200 школ, но Питт - единственный, у кого есть исчерпывающие данные. Остальные просто имеют базовые данные, такие как Гарвард. Я также оставил некоторые данные для Питта ради краткости, но дайте мне знать, если вы хотите, чтобы я включил остальные.

Изменить: я попытался вынуть * в science_majors вниз, а затем запустить rake db:seed, но это ничего не изменило.

4b9b3361

Ответ 1

Вы получаете ошибку кодирования, потому что ваша файловая система не настроена для кодирования даты, которую вы добавили (поскольку предположительно она включает в себя новые символы - возможно, в вашем URL-адресе карты HTML-объекта, который не существовал в предыдущем семена данных).

Следующая ошибка должна устранить эту ошибку, установив локаль UTF-8 на вашем компьютере:

# from your command line
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
bundle

Преимущество установки языкового стандарта системы заключается в том, что все драгоценные камни (в будущем) будут объединены с использованием кодировки UTF-8.

EDIT:

В качестве альтернативы, если вы не хотите изменять системную кодировку, вы можете установить свою кодировку в масштабе всего проекта, указав стандарт кодирования в своем Gemfile:

if RUBY_VERSION =~ /1.9/ # assuming you're running Ruby ~1.9
  Encoding.default_external = Encoding::UTF_8
  Encoding.default_internal = Encoding::UTF_8
end

Ответ 2

Добавить

#encoding: utf-8

в верхней части файла

Ответ 3

Вы также можете попробовать export RUBYOPT="-KU -E utf-8:utf-8" как упоминалось в этом потоке GH

Ответ 4

Если у вас возникла эта проблема в контейнере для рубинового докера, вы можете либо установить LANG=C.UTF-8:

docker run -it --rm -e LANG=C.UTF-8 ruby ...

или посмотреть эту проблему.

Ответ 5

Как и другие, я добавил #encoding: utf-8 в начало моего файла (в данном случае, seed.rb), но все равно не смог заставить задачу рейка работать.

Интересно, что друг рекомендовал, чтобы я удалял дополнительные результирующие комментарии из верхней части файла семени, так что осталось только #encoding: utf-8.

Что бы вы знали - это сработало.

Ответ 6

В вашем файле семени есть недопустимый символ, в моем случае изменяются одинарные кавычки из `to '.