Saturday, November 17, 2012

Multiple ways to import your data in ror

1. Importing the csv data from a specific location through Rake Task
URL of that blog - http://rorguide.blogspot.in/2012/11/importing-csv-data-from-specific.html

2. Importing the csv data by browsing and uploading csv from application screen
URL of that blog - http://rorguide.blogspot.in/2012/11/importing-csv-data-by-browsing-and.html

Importing the csv data by browsing and uploading csv from application screen

Importing the csv data by browsing and uploading csv from application screen

Given below code will be placed in view which will allow user to browse file to upload from view. Notice the code
:html => { :multipart => true }
which is mandatory for uploading file.

<% form_for :dump, :url=>{:controller=>"imports", :action=>"csv_import_eqdata2"}, :html => { :multipart => true } do |f| -%>
 <table border=1>
   <tr>
     <td>
      <label for="dump_file">
        Select a EQ Data CSV File2 :
      </label>
     </td>
     <td >
       <%= f.file_field :file -%>
     </td>
   
     <td colspan='2'>
       <%= submit_tag 'Submit' -%>
     </td>
   </tr>
 </table>
<% end -%>

==================
After upload when user will hit submit button, it will call imports controller, csv_import_eqdata2 action. Here are the codes which will be written in controller:

def csv_import_eqdata2 
  @parsed_file=CSV::Reader.parse(params[:dump][:file])
  n=0
     
  @parsed_file.each  do |row|
       
     rsymbol = row[0].strip if !row[0].blank?
     rseries = row[1]
     rtottrdqty = row[2]
     rtottrdval = row[3]

     @eqrawdatas = Eqrawdata.find(:all, :conditions => ["symbol='#{rsymbol}' and series ='#{rseries}' and tottrdqty ='#{rtottrdqty}' and tottrdval ='#{rtottrdval}' and deleted_at is null"])
     
     presentinlotsize = Lotsizedata.find(:first, :conditions =>["symbol='#{rsymbol}' "])

     #Accept only those records whose series is EQ only
     if @eqrawdatas.blank? && !rsymbol.blank? && !rseries.blank? && (rseries == "symbol" or rseries == "EQ") && !presentinlotsize.blank?
     c=Eqrawdata.new
     c.symbol= rsymbol
     c.series=rseries
     c.tottrdqty = rtottrdqty
     c.tottrdval= rtottrdval

     if c.save
        n=n+1
        GC.start if n%50==0
     end
     flash.now[:message]="CSV Import Successful,  #{n} new records added to data base"
     end
     end
   return redirect_to(eqdatalist_url)
end

Importing the csv data from a specific location through Rake Task

1. Importing the csv data from a specific location through Rake Task:

We can import data from csv file which is placed in csv folder in our Rails application root directory. Here we checks that csv file name should start with eq2 and ends with .csv, only these csv files should be picked to parse. All such csv files will be parsed. Place the given below code in "lib/tasks" folder as a rake task and run to import data.

Here are code details:


namespace :import do

  desc 'import csv files of eq2'
  task :eq2 => :environment do
    root = Rails.root.to_s
    require 'csv'

    #importing eq2  csv files where name starting from eq2 and ending with csv
    eq_files = Dir.glob("#{root}/csv/eq2*.csv")
    puts "Found eq2 csv file named  #{eq_files}"

    if !eq_files.blank?
      eq_files.each do |eq_file|
        puts "eq1 file is not blank #{eq_file}"
       
        @parsed_file = CSV::Reader.parse(File.open(eq_file, "rb"))
        n = 0
        @parsed_file.each_with_index do |row, i|
          next if i == 0 || i == 1
          break if row[2].blank?

          rsymbol = row[2].strip if !row[0].blank?
          rseries = row[3]

          presentinmaster = Masterdata.find(:first, :conditions =>["nse_symbol='#{rsymbol}' "])
          
          #Accept only those records which fulfill following conditions
          if !presentinmaster.blank? !rsymbol.blank? && !rseries.blank? && (rseries == "symbol" or rseries == "EQ")
            c=Eqmasterdata.new
            c.symbol= rsymbol
            c.series=rseries
            c.masterdatas_id = presentinmaster.id
            if c.save
              puts "CSV Import Successful,  #{n} new records added to data base"
              n=n+1
              GC.start if n%50==0
            else
              puts "EQ2 could not be save, error is #{c.errors}"
              #else writing error in different table
              AllError.create(:error_of => 'EQ2', :error_detail => c.errors, :error_summary => "Data not saved")
            end
          end

        end
      end
    end
  end
end

Friday, November 16, 2012

Multiple ways to export your data in ruby on rails

1. Prompting and letting user save csv in a particular folder:

Export excel from Rails application - User gets a link on view and when user clicks on that link a prompt comes asking user to save the exported excel on clients computer at desired location. In this case, you can create excel view and perform view formatting as we do with html page.

URL of blog - prompting-and-letting-user-save-csv-in-particular-folder


2. Saving the csv at a particular pre-defined folder:

Export csv at a particular pre-defined folder specified in rails application: User gets a link on view and when user clicks on that link user is not asked about the location for saving the csv, csv is exported and saved at pre-defined location. In this case, you cannot create excel view.

URL of blog - export-csv-at-particular-pre-defined-folder

CSV reader syntax change in Ruby 1.8.7 and Ruby 1.9.2

The way CSV file is opened in Ruby 1.8.7 and in Ruby 1.9.2 are different, here are the syntax:


@parsed_file = CSV::Reader.parse(File.open(restaurant_file, "rb"))
when running from ruby 1.8.7

new
@parsed_file = CSV.read(restaurant_file)
when running from ruby 1.9.2

Saturday, June 2, 2012

Fixed error "_gedit_app_get_window_in_viewport: assertion `GEDIT_IS_WINDOW (window)' failed"

On Ubuntu when I try to open a file through gedit, I get following error:

"** (gedit:2679): CRITICAL **: _gedit_app_get_window_in_viewport: assertion `GEDIT_IS_WINDOW (window)' failed"


To fix the problem first remove gedit by command:
- sudo apt-get remove gedit

Then install gedit again:
- sudo apt-get install gedit

Saturday, February 4, 2012

Export csv at a particular pre-defined folder in rails application

Export excel from Rails application - User gets a link on view and when user clicks on that link user is not asked about the location for saving the csv, csv is exported and saved at pre-defined location. In this case, you cannot create excel view.
Saving the csv at a particular pre-defined folder
Code snippets:

1. Add action on 'eqrawdatas' controller: 
def export_list
  require 'csv'
  symboldetails = Masterdata.find(:all)
  config = read_config_exp  

    outfile = File.open(File.join(config['event_export_path'],"export_data.csv"), "w")
      CSV::Writer.generate(outfile) do |csv|
      csv << Array["Uniq Symbol", "Symbol", "Data Date" ]
      symboldetails.each do |symboldetail|
        arr = []
    arr = Array[symboldetail.uniqsymbol, symboldetail.symbol, symboldetail.data_date.strftime("%b %d, %Y")  ]
        csv << arr                                   
      end
    end
    outfile.close 
  return redirect_to :back
end

2. In the same controller, add a private method
  private
  #read the config file

  def read_config_exp
    config_file = File.open("#{RAILS_ROOT}/misc/export_event.yml")
    erb = ERB.new(config_file.read)
    all_configs = YAML.load(erb.result(binding))
    dir = all_configs["All"]["event_export_path"]
    Dir.mkdir(dir) unless File.exists?(dir)
    all_configs['All']
  end

3. Create export_event.yml file in misc folder inside rails application
In rails application misc folder, create export_event.yml file. In this file it will export the csv data in C:\exported_csv folder:
All:
  event_export_path: C:\exported_csv

4. Add link on view:
<%= link_to("Export EQ Date Data List", :controller => :eqrawdatas, :action => :export_list) %>
 

Prompting and letting user save csv in a desired folder

Export excel from Rails application - User gets a link on view and when user clicks on that link a prompt comes asking user to save the exported excel on clients computer at desired location. In this case, you can create excel view and perform view formatting as we do with html page.
Prompting and letting user save csv in a desired folder:
Code snippets:

1. Add in routes:
map.fumasterdatalist 'chart/fumasterexcel', :controller => "chart", :action => "fumaster_excel"

2. Add link on view:
   <%= link_to "Export FU List as Excel", {:controller=> "chart", :action=> "fumaster_excel"}  %>

3. Add action on controller
  def fumaster_excel
      @oprawdatas= Expdatedata.find(:all, :order=> "exp_date asc")
      headers['Content-Type'] = "application/vnd.ms-excel"
      headers['Content-Disposition'] = 'attachment; filename="fuexpreport.xls"'
      headers['Cache-Control'] = ''
      render(:layout=>false)
    end

4. Create a view page which will be exported in excel:

<table "border=1px" cellpadding="2" style="margin: 20px 40px">
  <tr>
   <th>Sl. No.</th>
   <th>ID</th>
   <th>Instrument</th>
    <th>Symbol</th> 
    <th>Created_At&nbsp;&nbsp;&nbsp;</th>
  </tr>

<% i = 0 %>
<% @oprawdatas.each do |import| %>
  <tr>
  <td><%=i = i + 1 %></td>
  <td><%=h import.id %></td>
    <td><%=h import.instrument %></td>
    <td><%=h import.symbol %></td> 
    <td><%=h import.created_at.strftime("%b %d, %Y") %></td>
    <td><%= link_to 'Destroy', {:controller=> "oprawdatas", :action=> "destroy", :id=> import.id}, :confirm => 'Are you sure you want to delete the record?' %></td>
  </tr>
<% end %>
</table>



"src/rbae.c:13:27: fatal error: Carbon/Carbon.h: No such file or directory" while installing rb-appscript (0.6.1) on ubuntu

While running bundle install, got following error:
Installing rb-appscript (0.6.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /home/ritesh/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
extconf.rb:44: Use RbConfig instead of obsolete and deprecated Config.
create /home/ritesh/.rvm/gems/ruby-1.9.3-p0@koodrails/gems/rb-appscript-0.6.1/src/osx_ruby.h ...
create /home/ritesh/.rvm/gems/ruby-1.9.3-p0@koodrails/gems/rb-appscript-0.6.1/src/osx_intern.h ...
creating Makefile

make
Makefile:226: warning: overriding commands for target `/home/ritesh/.rvm/gems/ruby-1.9.3-p0@koodrails/gems/rb-appscript-0.6.1/lib'
Makefile:224: warning: ignoring old commands for target `/home/ritesh/.rvm/gems/ruby-1.9.3-p0@koodrails/gems/rb-appscript-0.6.1/lib'
compiling src/rbae.c
src/rbae.c:13:27: fatal error: Carbon/Carbon.h: No such file or directory
compilation terminated.
make: *** [rbae.o] Error 1


Gem files will remain installed in /home/ritesh/.rvm/gems/ruby-1.9.3-p0@koodrails/gems/rb-appscript-0.6.1 for inspection.
Results logged to /home/ritesh/.rvm/gems/ruby-1.9.3-p0@koodrails/gems/rb-appscript-0.6.1/./gem_make.out
An error occured while installing rb-appscript (0.6.1), and Bundler cannot continue.
Make sure that `gem install rb-appscript -v '0.6.1'` succeeds before bundling.




Yet looking for solution to fix the issue, if someone can help.

Tuesday, January 31, 2012

Getting error "can't activate sqlite3 (~> 1.3.5), already activated sqlite3-1.3.4" when upgrading to Rails 3.2

Upgradation from Rails 3.1 to Rails 3.2 done successfully. When starting server, getting error :

Exiting
/home/ritesh/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler/rubygems_integration.rb:153:in `block in replace_gem': Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (can't activate sqlite3 (~> 1.3.5), already activated sqlite3-1.3.4. Make sure all dependencies are added to Gemfile.) (LoadError)
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:3:in `<top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `block in require'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:234:in `block in load_dependency'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:234:in `load_dependency'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:48:in `resolve_hash_connection'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:23:in `spec'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/railtie.rb:76:in `block (2 levels) in <class:Railtie>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/base.rb:709:in `<top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/omniauth-identity-1.0.0/lib/omniauth/identity/models/active_record.rb:6:in `<module:Models>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/omniauth-identity-1.0.0/lib/omniauth/identity/models/active_record.rb:5:in `<module:Identity>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/omniauth-identity-1.0.0/lib/omniauth/identity/models/active_record.rb:4:in `<module:OmniAuth>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/omniauth-identity-1.0.0/lib/omniauth/identity/models/active_record.rb:3:in `<top (required)>'
from /home/ritesh/projects/projects/crowd/app/models/crowd/credential.rb:1:in `<top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:469:in `load'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:469:in `block in load_file'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:468:in `load_file'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:353:in `require_or_load'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:502:in `load_missing_constant'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:190:in `each'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:190:in `const_missing'
from /home/ritesh/projects/projects/crowd/config/initializers/omniauth.rb:4:in `block in <top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/omniauth-1.0.0/lib/omniauth/builder.rb:7:in `initialize'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.0/lib/action_dispatch/middleware/stack.rb:43:in `new'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.0/lib/action_dispatch/middleware/stack.rb:43:in `build'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.0/lib/action_dispatch/middleware/stack.rb:112:in `block in build'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.0/lib/action_dispatch/middleware/stack.rb:112:in `each'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.0/lib/action_dispatch/middleware/stack.rb:112:in `inject'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.0/lib/action_dispatch/middleware/stack.rb:112:in `build'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/engine.rb:470:in `app'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/application/finisher.rb:32:in `block in <module:Finisher>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `instance_exec'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `run'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `each'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `run_initializers'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/application.rb:136:in `initialize!'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/ritesh/projects/projects/crowd/spec/dummy/config/environment.rb:5:in `<top (required)>'
from /home/ritesh/projects/projects/crowd/spec/dummy/config.ru:4:in `require'
from /home/ritesh/projects/projects/crowd/spec/dummy/config.ru:4:in `block in <main>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /home/ritesh/projects/projects/crowd/spec/dummy/config.ru:1:in `new'
from /home/ritesh/projects/projects/crowd/spec/dummy/config.ru:1:in `<main>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands/server.rb:46:in `app'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands/server.rb:70:in `start'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands.rb:50:in `tap'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands.rb:50:in `<top (required)>'
from /home/ritesh/projects/projects/crowd/spec/dummy/script/rails:6:in `require'
from /home/ritesh/projects/projects/crowd/spec/dummy/script/rails:6:in `<top (required)>'
from script/rails:6:in `load'
from script/rails:6:in `<main>'


To fix the error:

Change the sqlite version in .gemspec from
s.add_development_dependency "sqlite3"
to
s.add_development_dependency "sqlite3" , "~> 1.3.5"

and run 'bundle install'

Getting error 'undefined method `before_dispatch' for class `Rails::Rack::Logger' (NameError) '

Upgradation from Rails 3.1 to Rails 3.2 done successfully. When starting rails server getting following error:

/home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method': undefined method `before_dispatch' for class `Rails::Rack::Logger' (NameError)
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method_chain'
from /home/ritesh/projects/projects/crowd/spec/dummy/config/initializers/quite_assets.rb:6:in `block in <top (required)>'
from /home/ritesh/projects/projects/crowd/spec/dummy/config/initializers/quite_assets.rb:2:in `class_eval'
from /home/ritesh/projects/projects/crowd/spec/dummy/config/initializers/quite_assets.rb:2:in `<top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:245:in `load'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:245:in `block in load'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:245:in `load'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/engine.rb:587:in `each'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/engine.rb:587:in `block in <class:Engine>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `instance_exec'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `run'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `each'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `run_initializers'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/application.rb:136:in `initialize!'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/ritesh/projects/projects/crowd/spec/dummy/config/environment.rb:5:in `<top (required)>'
from /home/ritesh/projects/projects/crowd/spec/dummy/config.ru:4:in `require'
from /home/ritesh/projects/projects/crowd/spec/dummy/config.ru:4:in `block in <main>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /home/ritesh/projects/projects/crowd/spec/dummy/config.ru:1:in `new'
from /home/ritesh/projects/projects/crowd/spec/dummy/config.ru:1:in `<main>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands/server.rb:46:in `app'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands/server.rb:70:in `start'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands.rb:50:in `tap'
from /home/ritesh/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands.rb:50:in `<top (required)>'
from /home/ritesh/projects/projects/crowd/spec/dummy/script/rails:6:in `require'
from /home/ritesh/projects/projects/crowd/spec/dummy/script/rails:6:in `<top (required)>'
from script/rails:6:in `load'
from script/rails:6:in `<main>'

To fix the error, 

Place the following code in config/initializers/quiet_assets.rb
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
  def call_with_quiet_assets(env)
    previous_level = Rails.logger.level
    Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
    call_without_quiet_assets(env).tap do
      Rails.logger.level = previous_level
    end
  end
  alias_method_chain :call, :quiet_assets
 end


Update Rails 3.1 to Rails 3.2


In Gemfile, change following versions of assets and rails

gem 'rails', '3.2.0'

group :assets do
  gem 'sass-rails', "  ~> 3.2.3"
  gem 'coffee-rails', "~> 3.2.1"
  gem 'uglifier', '>= 1.0.3'
end

Run 'bundle update'

Sunday, January 1, 2012

Getting error "File Error: data may have been lost" while using spreadsheet and exporting excel

I am using "Spreadsheet" gem with Rails 2.3.8. Microsoft Office 2007 is installed on my system.
I successfully fitted the code snippets in one of my controller.
I just wrote the code to create Worksheet and pushed one row record in it.
Number of records pushed in that row is around 330.
When I export the spreadsheet/excel, I got following error:



"File Error: data may have been lost"

Clicked on Ok and it created the excel file with the File Type "Microsoft Office Excel 97-2003 Worksheet" with one sheet having 1 row.
When closely analyzed the sheet, I found that Number of maximum columns that can be in that sheet is only 256 and as I was trying to have around 330 columns hence I was getting the error.