Lee Hughes8,380 Points
Best practices for importing a csv file for Select2
I have downloaded the example app provided https://github.com/jseifer/rails-select2-example and have started to play around with it. I really love the feature but I need it to use a country drop down with corresponding cities.
I have found a csv of countries https://github.com/railscasts/088-dynamic-select-menus-revised/blob/master/store-after/countries.csv
What would be the best way to integrate these two together?
I'm researching using an import (require) feature and also trying to use the name,abbreviation,country_id which are referenced on the csv somehow.
If anyone can point me in the right way it would be most appreciated.
Andrew ChalkleyTreehouse Guest Teacher
Hello Lee Hughes
I've put a couple of videos together to help you out. I answered your question in two parts, Seeding Databases with CSV Files...
...and Updating Select2 Drop-downs via AJAX.
For those who are interested in following along with parts 1 and 2 you can download the files here.
Whilst you did ask for how to import CSV files for countries and states, you may be able to find a Gem that would take care of that aspect of your project however I showed the CSV approach like you asked for as it may be helpful in other seeding scenarios.
is this always going to b available? i dont have time to follow it now
hey guys can someone help me out here, i have been stuck on this for long noe, am running rails 3.2.16 and i am trying to generate my first status on the rails dev track here at treehouse and i have the following problem,thanks
When generating my first status, that is when I do the localhost/statuses I have the following error:
ExecJS::RuntimeError in Statuses#index
Showing C:/Users/NEBELYN/ruby1/gopbook/app/views/layouts/application.html.erb where line #6 raised:
gem 'rails', '3.2.16'
Bundle edge Rails instead:
gem 'rails', :git => 'git://github.com/rails/rails.git'
Gems used only for assets and not required
in production environments by default.
group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3' end
To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'
To use Jbuilder templates for JSON
Use unicorn as the app server
Deploy with Capistrano
To use debugger
Adam Faur2,365 Points
@Pavey Nganpi Typically that means that need to gem install therubyracer however it looks like you have that installed so heres my stab at it..
I saw in your gemfile you are using...
gem 'therubyracer', :platforms => ruby
Have you tried changing your gem file to read:
Then running bundle install.
Also, as a test you might try running:
bundle exec rake assets:precompile --trace
and see if you have any errors.
I don't use windows and don't know if you are, but I saw some things indicating that using the , :platforms => ruby does not work in some instances. I have included sources below for more information. Hopefully this helps, but if not I hope that Andrew might be able to shed some light on this one as well.
http://stackoverflow.com/questions/8362458/error-when-running-rails-app-execjsruntimeerror http://www.railszilla.com/rails-3-coffescript-execjs/rails http://stackoverflow.com/questions/8421321/does-using-platforms-in-your-gemfile-work
thanks for the reply, i did try with gem rubyracer and nothing changed, so i tried the one above, still nothing, also when i try rubyrace and run install bundle it runs and gives an error saying i have to intall libv8, which i tried to install by running install libv8 --version"188.8.131.52". this ran and then gave an error saying it cant find the path, i have been on this pb for the past 2 days, i feel discouraged about learning rail
Adam Faur2,365 Points
@Pavey Nganpi Don't be discouraged!
Many have been right there in your shoes before.
It's a constant challenge to overcome a new problem but don't let it get you down.
Remember, confusion is the very first step of learning and this is the really cool stuff, so, it is usually the most confusing =).
I would like to recommend that you look at some more resources which I included at the bottom of this message.
Based on your last answer you may need a solution to install libv8 and since it is not working (by installing therubyracer) you might try installing nodejs to solve this dependency.
You can find a windows version of the installer here:
The short answer is since nodejs uses libv8 exclusively as its engine you will get it by installing nodejs.
Based on what some other people are saying you may be able to install rails from here to get libv8 but since you already have rails installed it might just confuse things further. (RailsInstaller.org)
thanks adam, i appreciate
Adam Faur2,365 Points
Once you install node, you should now be able to remove:
from your gem file, then run bundle install
By having nodejs installed you should now have libv8.
You should not need therubyracer any longer and by keeping it you might encounter another error.
@adam faur hey, Adam,since i have node installed and its the javacript engine for rails, is it possible to build stuff in my rails app using node.js? thanks
yh sure i will, :)
Adam Faur hi, i followed exactly what was explained in the rails4 todo lists tutorial here at treehouse on how to install rpec, but i didnt have the directories helpers,views, controller, and the rest, pls how can i generate theses directories,thanks
ok thanks adam