Incorrect byte sequence in US-ASCII (argument error) when I run rake db: seed in Rails

When I run rake db:seed in my Rails application, I get this error:

Incorrect byte sequence in US-ASCII (argument error)

I just added science_majors all the way to my seed file, and now when I run rake db:seed , it gives me this error:

invalid byte sequence error

Why is this and how can I fix it?

part of 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="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" 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="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" 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 

I left all the other colleges. I still have 200 schools, but Pitt is the only one who has comprehensive data. The rest just have basic data like Harvard. I also left some data for Pitt for the sake of brevity, but let me know if you want me to include the rest.

Edit: I tried to science_majors * in science_majors down and then run rake db:seed , but that didn't change anything.

+73
ruby-on-rails rake argument-error
Jun 10 '13 at 19:49
source share
6 answers

You get an encoding error because your file system is not configured to encode the date you added (since it supposedly includes new characters - perhaps in your map URL an HTML object that did not exist in the previous data seeds).

The following error should resolve this error by setting the UTF-8 locale on your computer:

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

The advantage of setting the system locale is that all gems (in the future) will be combined using the UTF-8 encoding.

EDIT:

Alternatively, if you do not want to change the system encoding, you can set your encoding throughout the project by specifying the encoding standard in your 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 
+146
Jun 10 '13 at 19:52
source share

Add

 #encoding: utf-8 

at the top of the file

+61
Jun 10 '13 at 19:53
source share

You can also try export RUBYOPT="-KU -E utf-8:utf-8" as mentioned in this GH thread

+21
Oct 02 '15 at 20:38
source share

If you have this problem in a ruby ​​docker container, you can either set LANG=C.UTF-8 :

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

or see this problem .

+10
Aug 19 '16 at 20:12
source share

Like others, I added #encoding: utf-8 to the top of my file (in this case, seed.rb), but still couldn't get the rake task to work.

Interestingly, a friend recommended that I remove the additional resulting comments from the top of the seed file, so that only #encoding: utf-8 remains.

What would you know - it worked.

+7
Oct 22 '13 at 3:06 on
source share

There is an invalid character in your seed file, in my case the single quotes from `to 'change.

+1
Mar 20 '14 at 17:02
source share



All Articles