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]
Archive for the ‘Ruby on Rails’ Category
Rails page caching – custom path – .htaccess configuration
Posted in Ruby on Rails on October 29, 2011 | Leave a Comment »
Rails Page caching – Changing the default ‘public’ path
Posted in Ruby on Rails on October 29, 2011 | Leave a Comment »
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] [...]
[Dreamhost] Rails Migrations and ‘Can‘t connect to local MySQL
Posted in installations, Ruby on Rails on October 27, 2011 | Leave a Comment »
Try the following; rake environment RAILS_ENV=production db:migrate instead of just; rake db:migrate
Rails – Group and count
Posted in Ruby on Rails, tagged Ruby on Rails on October 1, 2011 | Leave a Comment »
User.count(field, :group => [:name], :conditions => {:active => true}) To get distinct count; pass “:distinct => true”
Rails – Creating a custom primary key and foreign key
Posted in Ruby on Rails, tagged Ruby on Rails on October 1, 2011 | Leave a Comment »
class User < ActiveRecord::Base has_one :account, :primary_key => :account_index, :foreign_key=> :account_index end class Account< ActiveRecord::Base belongs_to :user end
Import CSV Using Rails Migration
Posted in Ruby on Rails, tagged Ruby on Rails on September 30, 2011 | Leave a Comment »
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
CSV parsing issues – MalformedCSVError, “Unquoted fields do not allow ” + “\\r or \\n
Posted in Ruby on Rails, Weird Errors, tagged bug fixes, Ruby on Rails on September 30, 2011 | Leave a Comment »
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, [...]
uninitialized constant CSV/FasterCSV
Posted in Ruby on Rails, Weird Errors, tagged bug fixes, Ruby on Rails on September 30, 2011 | Leave a Comment »
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”)
FasterCSV plus support for Ruby 1.9 issue fix
Posted in Ruby on Rails, Weird Errors, tagged bug fixes, Ruby on Rails on September 30, 2011 | Leave a Comment »
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.
Undo scaffolding in rails
Posted in Ruby on Rails, tagged Ruby on Rails on September 30, 2011 | Leave a Comment »
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>