Rails 3.1+ and GeoIP database file location/access - ruby-on-rails-3.1

This question is related to Rails - Where I have to store data file (.dat) in my rails project - GeoIp City database . I have a rails 3.2 app. I am trying to run:
#geoip = GeoIP.new('GeoLiteCity.dat')
In one of my app's controllers. I unzipped the 'GeoLiteCity.dat' file into the /public folder. I am getting the error "No such file or directory - GeoLiteCity.dat".
I've experimented with putting it in the images assets pipeline folder and some random other places. I continue to get the same error. Not sure how to access this file. Any ideas on what I'm doing wrong or how to access it best with the assets pipeline?

Try referencing it via the full path:
#geoip = GeoIP.new("#{Rails.root}/public/GeoLiteCity.dat")
On a side note, it's probably not a big deal, but I wouldn't put the file in your public directory.

Related

google-drive-ruby: upload file to a folder duplicates the file in the folder and root path

I have writen a Ruby script to lookup for documents with a given date and upload them to Google Drive by using the google-drive-ruby gem. I have a folder inside of the gdrive root path where I want to place the files, and I access it using collection_by_title and then uploading the file by using the .add method.
The problem is that the files are being uploaded each one two times, one to the folder I want and another one to the root path of my GDrive. Any thoughts?
This is the method where the file gets uploaded:
def upload_document(file, folder_code)
folder = #session.collection_by_title("#{folder_code}")
path = "#{#basedir}/#{folder_code}/#{file}"
folder.add(#session.upload_from_file(path, file, convert: false))
end
EDIT: Methods and variables translated to english.
Each time the method upload_document is triggered, one copy of the file gets uploaded to the folder and another copy gets uploaded to the root path of gdrive.
Example: Method upload_document gets called providing the file (454327.pdf) and the code of the folder where it has to be uploaded in gdrive ("1"). I build the folder object by using collection_by_title, I build the path where the file is located in my local network, and finally the file gets uploaded using upload_from_file. At this point, two copies of the file had been uploaded, one to the root path of gdrive (which I don't want) and another one to the right folder in gdrive.
I received an answer from the gem creator explaining what is happening and my script is finally working as I expected.
https://github.com/gimite/google-drive-ruby/issues/260
The thing is that the file is firstly uploaded to the root by default and then .add just moves the file to the selected collection, so the file needs to be removed from root after the move operation is completed.
#session.root_collection.remove(file)

Dajaxice not found on production server

I have a Django 1.4 project, running on Python 2.7 in which I'm using Dajaxice 0.5.4.1. I have set it up on my development machine (Windows 7) and everything works perfectly. However when I deploy my app to production server (Ubuntu 12.04) I get 404 error for dajaxice.core.js file and cannot resolve this problem no matter what. Production server works with exactly the same versions of all software.
My project structure looks like this:
/myproject
/myproject/myproject-static/ <-- all the static files are here
/myproject/myproject-static/css/
/myproject/myproject-static/img/
/myproject/myproject-static/js/
/myproject/templates/
/myproject/myproject/
/myproject/main/
/myproject/app1/
/myproject/app2/
/myproject/app3/
etc.
I was following the Dajaxice installation steps here and put everything in its place (in settings.py, ˙urls.pyandbase.html` files).
My settings.py file has also these values:
from unipath import Path
PROJECT_ROOT = Path(__file__).ancestor(3)
STATIC_ROOT = ''
STATIC_URL = '/myproject-static/'
STATICFILES_DIRS = (
PROJECT_ROOT.child('myproject-static'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'dajaxice.finders.DajaxiceFinder',
)
DAJAXICE_MEDIA_PREFIX = "dajaxice"
DAJAXICE_DEBUG = True
I have an Alias directive in my django.conf file which looks like this:
Alias /myproject-static/ "/path/to/myproject/myproject-static/"
I did collectstatic on my production server and got all static files collected within few folders in the root of my project. So, now when I look at my deployed web site, I can see that CSS is properly applied, JavaScript is working fine and navigation around the site works as intended. Everything is fine except Ajax is totally broken since dajaxice.core.js is never included.
My project folder structure after collecting static looks like this:
/myproject
/myproject/myproject-static/ <-- all the static files are originally here
/myproject/myproject-static/css/
/myproject/myproject-static/img/
/myproject/myproject-static/js/
/myproject/templates/
/myproject/admin/ <-- folder created with 'collectstatic' command
/myproject/css/ <-- folder created with 'collectstatic' command
/myproject/dajaxice/ <-- dajaxice.core.js is located here
/myproject/django_extensions/ <-- folder created with 'collectstatic' command
/myproject/img/ <-- folder created with 'collectstatic' command
/myproject/js/ <-- folder created with 'collectstatic' command
/myproject/myproject/
/myproject/main/
/myproject/app1/
/myproject/app2/
/myproject/app3/
etc.
Am I doing something completely wrong with my static files here?
What else should I try to fix this simple error?
Have you check if as the rest of the assets, dajaxice.core.js is inside your static/dajaxice folder? If not, the issue could be related with a miss configuration of the STATICFILES_FINDERS, check Installing dajaxice again
Another usual issue with collectstatic and dajaxice is to run the first using --link Are you using this option?
Hope this helps
I spend several hours grappling with this problem. It was crazy because everything worked great on my dev environment, but not on the test server even though all the dajax and dajaxice settings were on a common base settings file. I never got it to work using the standard route. But this is a very easy fix:
1) Download dajaxice.core.js into whatever static directory pleases you. You can find the js in your the dajaxice directory in your project root:
project/dajaxice/dajaxice.core.js
In my case, I put the file in static/js alongside all my other js libraries.
2) On your web page, replace this:
{% dajaxice_js_import %}
with a normal, everyday link to the js library. In my case:
<script src="/static/js/dajaxice.core.js" type="text/javascript"></script>
Unfortunately, this patch only works for developed code. If you usedo it in the development environment, new dajaxice code will be registered in the original project/dajaxice/ location and so the file will have to be copied to static after any new code is developed.

Update CodeIgniter from version 1.7.2 to 2.0.0 - class CI_Controller not found

I'm trying to update my project from CI version 1.7.2 to CI v. 2.0.0 (then I will update to next versions - but first I need to deal with that).
So:
Path to my CI is:
/home/user/www/mysite. That’s all right, it’s written here: http://codeigniter.com/user_guide/installation/upgrade_200.html That I should replace my system folder (except application folder) with this from v2.0.
I copied these directories from 2.0.0’s system folder (that’s core, database, fonts, helpers, language, libraries) and replaced older ones. I’ve done all other things - and after trying to launch my new version of CI - it shows
Fatal error: Class ‘CI_Controller’ not found in/home/user/sitesystem/application/controllers/test.php on line 3.
MY /system/core folder contains file Controller.php and it starts with
class CI_Controller
- so everything should work fine - what’s going on?
First, in CI 2, the application folder is in the root dir, not under the system directory. And second, if you watch closely your error say:
/home/user/sitesystem/application/
and you wrote previously, that the path is:
/home/user/www/mysite
so i would check this 2 things first.

no route matches for assets/images in Rails

Working on rails, images are not visible and giving error.
Started GET "/assets/home.png" for 127.0.0.1 at 2012-06-19 12:23:24 +0530
Served asset /home.png - 404 Not Found (24ms)
ActionController::RoutingError (No route matches [GET] "/assets/home.png"):
I have used command
rake assets:precompile
production.rb
config.assets.compress = true
config.assets.compile = false
application.rb
config.assets.enabled = true
config.assets.version = '1.0'
Thanks for any help!
Actually you cannot reference your image with /assets/home.png path.
It will work in development mode, but in production all of your assets have a fingerprint in their filename (read this http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark)
That's why, in assets-pipeline enabled applications you need to reference all of your assets using helper methods. Read this doc to learn about the different helpers available in Ruby, JS and Sass files: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
The lack of a fingerprint in the file request suggests that you are running this in development. I am also going to guess that this is an app upgraded from an older version of Rails.
Any images need to be in the folder /assets/images for the pipeline to work.
Also, you do not need to precompile when in development mode.
Delete the public/assets folder, delete the folder tmp/cache/assets, and restart your server.
If this images are in the correct location, it should work.

How do you set the upload path for the Codeigniter upload library on a local machine?

I have the following path set as the upload_path for Upload library included with Codeigniter.
$this->upload_config['upload_path'] = './uploads/working/';
This path works fine on the remote server. However, when I'm debugging locally, it fails.
I have permissions set so the directory is writeable.
I added logging to the upload library and found that it is failing this check in the library:
! #is_dir($this->upload_path)
My development machine is a MacBook Pro running 10.6.2. I'm using MAMP Pro. My directory structure looks like:
app
cache
ci_1_7_2
html
- css
- images
- index.php
- js
- uploads
- large
- normal
- small
- working
Any help would be greatly appreciated. Thanks for your time.
When uploads folder is inside /application/ you can use:
$this->upload_config['upload_path'] = APPPATH . 'uploads/working/';
But for this structure, hardcode an absolute path or use:
$this->upload_config['upload_path'] = realpath(dirname(__FILE__)). '/uploads/working/';
Notice that APPPATH contains a trailing slash but realpath will strip the trailing slash.
When all else fails, use absolute paths.

Resources