Saat saya menjalankan aplikasi rake db:seed
saya Rails
, saya mendapatkan kesalahan ini:
urutan byte tidak valid di US-ASCII (Argument Error)
Saya baru saja menambahkan science_majors
dan turun ke file benih saya, dan sekarang ketika saya menjalankannya rake db:seed
memberi saya kesalahan ini:
kesalahan urutan byte tidak valid
Mengapa demikian, dan bagaimana cara memperbaikinya?
bagian dari biji. 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&source=s_q&hl=en&geocode=&q=university+of+pittsburgh&aq=&sll=40.444261,-79.970448&sspn=0.142165,0.251656&ie=UTF8&hq=university+of+pittsburgh&t=m&ll=40.443486,-79.958245&spn=0.010798,0.021038&output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?f=q&source=embed&hl=en&geocode=&q=university+of+pittsburgh&aq=&sll=40.431368,-79.9805&sspn=0.142165,0.251656&ie=UTF8&hq=university+of+pittsburgh&t=m&ll=40.443486,-79.958245&spn=0.010798,0.021038" 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&source=embed&hl=en&geocode=&q=University+of+Pittsburgh,+4200+Fifth+Ave,+Pittsburgh,+PA&aq=0&oq=uni&sll=40.444261,-79.970448&sspn=0.142165,0.251656&ie=UTF8&hq=University+of+Pittsburgh,+4200+Fifth+Ave,+Pittsburgh,+PA&ll=40.443486,-79.958245&spn=0.010798,0.021038&t=m&layer=c&cbll=40.441775,-79.956671&panoid=BgWQKMiSI1fpwP7JUF16Vg&cbp=12,45.25,,0,-3.34&output=svembed"></iframe><br /><small><a href="https://maps.google.com/maps?f=q&source=embed&hl=en&geocode=&q=University+of+Pittsburgh,+4200+Fifth+Ave,+Pittsburgh,+PA&aq=0&oq=uni&sll=40.431368,-79.9805&sspn=0.142165,0.251656&ie=UTF8&hq=University+of+Pittsburgh,+4200+Fifth+Ave,+Pittsburgh,+PA&ll=40.443486,-79.958245&spn=0.010798,0.021038&t=m&layer=c&cbll=40.441775,-79.956671&panoid=BgWQKMiSI1fpwP7JUF16Vg&cbp=12,45.25,,0,-3.34" 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
Saya meninggalkan semua perguruan tinggi lainnya. Saya memiliki 200 sekolah sejauh ini, tetapi Pitt adalah satu-satunya yang memiliki data lengkap sejauh ini. Sisanya hanya memiliki data dasar, seperti Harvard. Saya juga meninggalkan beberapa data untuk Pitt agar singkatnya, tetapi beri tahu saya jika Anda ingin saya menyertakan sisanya.
Sunting: Saya mencoba mengeluarkan *
in science_majors
ke bawah dan kemudian berlari rake db:seed
, tetapi itu tidak mengubah apa pun.
sumber
#encoding utf-8
ke bagian atas file Anda untuk memastikan bahwa itu dikodekan dengan benar, seperti yang dicatat oleh poster lain dengan cerdik.~/collegeanswers >> export LANG=en_US.UTF-8 ~/collegeanswers >> export LC_ALL="en_US.UTF-8" ~/collegeanswers >> bundle Using rake (10.0.4) . . Using i18n (0.6.1) Your bundle is complete! Use
bundle show [gemname] `untuk melihat di mana bundled gem dipasang. ~ / collegeanswers >> rake db: seed rake dibatalkan! `apa kamu tahu kenapa?rake
kesalahan Anda ? Permata Anda yang ada mungkin belum dikonfigurasi untuk bekerja dengan pengkodean sistem file Anda. Cobabbundle exec gem uninstall i18n
, kemudianbundle install
.invalid byte sequence in US-ASCII (ArgumentError)
. Saya baru saja mencoba apa yang Anda katakan dan mendapatkan kesalahan yang sama.Menambahkan
#encoding: utf-8
di bagian atas file
sumber
Anda juga dapat mencoba
export RUBYOPT="-KU -E utf-8:utf-8"
seperti yang disebutkan di utas GH inisumber
shotgun-0.9.1/bin/shotgun:94:in `[]': invalid byte sequence in US-ASCII (ArgumentError)
Jika Anda mengalami masalah ini dalam wadah buruh pelabuhan ruby, Anda dapat mengatur
LANG=C.UTF-8
:docker run -it --rm -e LANG=C.UTF-8 ruby ...
atau perhatikan masalah ini .
sumber
Seperti yang disarankan orang lain, saya menambahkan
#encoding: utf-8
ke bagian atas file saya (dalam hal ini, seed.rb), tetapi masih tidak bisa mendapatkan tugas rake untuk bekerja.Yang cukup menarik, seorang teman merekomendasikan agar saya menghapus komentar tambahan yang dihasilkan rel dari atas file seed sehingga hanya
#encoding: utf-8
tersisa.Apa yang akan Anda ketahui - itu berhasil.
sumber
Ada karakter yang tidak valid di file seed Anda, dalam kasus saya, mengubah tanda kutip tunggal dari `menjadi 'berhasil.
sumber