Feeds:
Posts
Comments

Archive for the ‘Ruby on Rails’ Category

If you have changed the default cache path in Rails, then you need to make the updates in apche config as well. The example config for ‘public/cache/’ dir; RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] # This directive will look in public/cache/ for cached files RewriteCond %{REQUEST_FILENAME} !-f RewriteRule !^cache/(.*) - [C] RewriteRule ^(.*)$ cache/$1 [QSA] # If nothing is found, send to rails RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

Read Full Post »

In config/environment.rb, change the page cache directory from the default by adding the following line inside the Rails::Initializer.run block. config.action_controller.page_cache_directory = RAILS_ROOT+”/public/cache/” Also make sure you change the rewrite rules in the webserver configuration. For Apache (public/.htaccess) the first two rules probably need to be changed to: RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] [...]

Read Full Post »

Try the following; rake environment RAILS_ENV=production db:migrate instead of just; rake db:migrate

Read Full Post »

User.count(field, :group => [:name], :conditions => {:active => true}) To get distinct count; pass  “:distinct => true”

Read Full Post »

class  User < ActiveRecord::Base has_one :account, :primary_key => :account_index, :foreign_key=> :account_index end class Account< ActiveRecord::Base belongs_to :user end

Read Full Post »

require ‘csv’ CSV.foreach(“#{RAILS_ROOT}/db/seed/file.csv”, encoding: “UTF-8″ ,:row_sep => “\r\n”) do |row| field1,field2,field3 = row Foo.create(:field1 => field1, :field2 => field2, :field3 => field3) end

Read Full Post »

Here, you need to consider 2 things. CSV’s auto line ending detection may be failing for some reason.  A likely cause could be fields that contain line endings different from those used to end lines. You should be able to solve this by setting the :row_sep manually. CSV.open(…, :row_sep => “\r\n”) If that doesn’t work, [...]

Read Full Post »

Ruby 1.9 has adopted FasterCSV as its built-in CSV library. However, it’s in the standard library rather than Ruby 1.9′s core, so you need to manually require it in the application. After adding a require ‘csv’ to your code, you can then do things such as CSV.parse(“this,is,my,data”) require ‘csv’ CSV.parse(“this,is,my,data”)

Read Full Post »

If you see the beow issue; Please switch to Ruby 1.9′s standard CSV library.  It’s FasterCSV plus support for Ruby 1.9′s m17n encoding engine. Remove fasterCSV from your Gemfile in the application. Bundler is trying to require FasterCSV because you have it specified in the Gemfile.

Read Full Post »

Undo scaffolding in rails

rails 3.0 or higher; rails generate scaffold <name> rails destroy scaffold <name> Also we can undo whatever we did with rails generate <something> By rails destroy <something>

Read Full Post »

Older Posts »