Tuesday, April 13, 2010

attachment_fu on Windows

When upload an image file with attachment_fu on windows, you will see there is an error such as 'Size is not included in the list' and you cannot upload the file to Amazon S3.

You can refer to the link "http://epirsch.blogspot.com/2008/01/fixing-attachmentfu-on-windows-like.html" to use attachment_fu_patch file but I cannot make it run because of lib path error.

Thus, I simply update the following three files and restart the server, which works great:
(1) %your_ruby_root%/lib/uby/1.8/tempfile.rb
def size
if @tmpfile
@tmpfile.fsync # added this line

def temp_data
if save_attachment?
f = File.new( temp_path )
return f.read
return nil

(3) $your_project/vender/plugins/attachment/lib/technoweenie/attachment_fu/backends/s3_backend.rb
def save_to_storage
if save_attachment?
(temp_path ? File.open(temp_path, "rb") : temp_data), # added , "rb"
:content_type => content_type,
:access => attachment_options[:s3_access]

@old_filename = nil

Thursday, April 8, 2010

missing mislav-will_paginate

After you install 'will_paginate', you may see the strange error like:

Missing these required gems:

You're running:
ruby at /usr/bin/ruby1.8
rubygems 1.3.5 at /home/ci/.gem/ruby/1.8, /usr/lib/ruby/gems/1.8

Run `rake gems:install` to install the missing gems.

And, even though you try to install 'mislav-will_paginate', it does not allow to install it.

Then, it is because you miss a source so that you need to add the following source as follows:

gem sources -a http://gems.github.com

Then, install:

gem install mislav-will_paginate

Wednesday, March 31, 2010

Nested form with form_remote_tag

You may have a nested form for category within a root form as follows. And, you may use 'form_remote_tag' but if you click on the submit button for the nested form, it submits the root form.

%= start_form_tag :action => 'create' %>

div id="categories">
% form_remote_tag (:update => 'categories',
:url => { :action => 'add_category' }) do %>
%= text_field_tag 'new_price' %>
%= submit_tag 'Add' %>
% end %>

I have a solution even though it does not look pretty. You can just insert another form_remote_tag above the nested form:

%= start_form_tag :action => 'create' %>

%# faked form to avoid to submit the main form when addding review %>
% form_remote_tag(:url=>{:action =>'add_item'})do %>
% end %>

div id="categories">
% form_remote_tag (:update => 'categories',
:url => { :action => 'add_category' }) do %>
%= text_field_tag 'new_price' %>
%= submit_tag 'Add' %>
% end %>

% end_form_tag %>

Tuesday, March 23, 2010

error: Data truncated for column

We canot alter a nullable column when it is empty at MySQL.

Thus, if I want to change the column 'size_column' that are null to non-nu;;able colume, I got the following error:

== VerificationTries: migrating ==============================================
-- change_column(:associations, :size_column, :integer, {:limit=>3, :null=>false, :default=>0})
rake aborted!
An error has occurred, all later migrations canceled:

Mysql::Error: Data truncated for column 'size_column' at row 1: ALTER TABLE `associations` CHANGE 'size_column' 'size_column' mediumint DEFAULT 0 NOT NULL

Friday, March 5, 2010

rcov error on Windows

I have the following error at "rake test:coverage" at rcov - I cannot install rcov-0.9.8:

0 tests, 0 assertions, 0 failures, 0 errors
c:/ruby-1.8.7-p72-i386-mswin32/lib/ruby/1.8/rexml/formatters/pretty.rb:131:in `[]': no implicit conversion from nil to integer (TypeError)

I've been lookin for the solution for this and I finally found one at "http://blog.andischacke.com/2009/03/problem-with-rcov-and-ruby-187.html".

I followed the step as he mentioned and it works now.
In summary, you need to change "lib/rcov/report.rb" of your rcov gem

if RUBY_VERSION == "1.8.6" && defined? REXML::Formatters::Transitive


if ["1.8.7", "1.8.6"].include?(RUBY_VERSION) && defined? REXML::Formatters::Transitive

Then, rerun

rake test:coverage

Monday, March 1, 2010

ThinkingSphinx GetLastError in Windows

I have the following error when I start or stop or restart the sphinx server after Iaccidentally restarted windows while sphinx was runnung:

WARNING: could not open pipe (GetLastError()=2)
FATAL: stop: error terminating pid 24256

Then, look up sphinx_conf.pid file and delete the file to remove pid 24256. That is, I have a log file named "searchd.development.pid" under "rails_project/log". The pid file has "24256". Thus, I deleted the file and "rake ts:start" and works well.

Thursday, February 25, 2010

rails commands for gem unpack

If you want to unpack gem file - you can only unpack gems that you have installed, for example memcache-client:

gem unpack memcache-client

You may also use rake:

rake gems:unpack GEM=memcache-client

But some reason, the second does not work for my msysgit.

And, there is a discussion to use gem or plugin (http://www.robbyonrails.com/articles/2009/01/13/question-plugins-or-gems-or-both)