Feeds:
Posts
Comments

Posts Tagged ‘Ruby on Rails’

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 »

@users.sort! { |a,b| a.name.downcase <=> b.name.downcase } Since strings are comparable, this will sort user objects alphabetically by name. To sort on login_count; @users.sort! { |a,b| a.login_count <=> b.login_count }

Read Full Post »

Define the custom_databse details in database.yml. For example; custom_database: adapter: mysql username: root password: database: custom_development All we need to do is to tell which models to use which connection. (E.g) class Results < ActiveRecord::Base establish_connection :custom_database end

Read Full Post »

Package versions may not be the latest one. These are the steps which I followed to set up my environment. You may want to download the latest source from web and then build it instead of using the download links mentioned here. sudo apt-get install build-essential sudo apt-get install openssl libssl-dev libmysqlclient-dev sudo apt-get install [...]

Read Full Post »

Older Posts »