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
@tmpfile.flush
@tmpfile.stat.size
else
0
end
end
(2)$your_project/vender/plugins/attachment/lib/technoweenie/attachment_fu.rb
def temp_data
if save_attachment?
f = File.new( temp_path )
f.binmode
return f.read
else
return nil
end
end
(3) $your_project/vender/plugins/attachment/lib/technoweenie/attachment_fu/backends/s3_backend.rb
def save_to_storage
if save_attachment?
S3Object.store(
full_filename,
(temp_path ? File.open(temp_path, "rb") : temp_data), # added , "rb"
bucket_name,
:content_type => content_type,
:access => attachment_options[:s3_access]
)
end
@old_filename = nil
true
end
Showing posts with label windows 7. Show all posts
Showing posts with label windows 7. Show all posts
Tuesday, April 13, 2010
Friday, March 5, 2010
rcov error on Windows
I have the following error at "rake test:coverage" at rcov 0.8.1.2 - 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
into
if ["1.8.7", "1.8.6"].include?(RUBY_VERSION) && defined? REXML::Formatters::Transitive
Then, rerun
rake test:coverage
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
into
if ["1.8.7", "1.8.6"].include?(RUBY_VERSION) && defined? REXML::Formatters::Transitive
Then, rerun
rake test:coverage
Friday, February 5, 2010
memcached in rails on Mac and Windows 7
Rails use the following caching methods:
Page Caching
Action Caching
Fragment Caching
Sweepers
SQL Caching
Page caching is to cache a full page in a controller logic. It ignores parameters and good for stateless page not for stateful page that we used to have. Page caches are always stored on disk.
Action caching is to cache a full action response in a controller logic. Before caching, we can add before_filter in order to add more functions such as authentication.
Fragment Caching is to cache a part of a page in a view logic. It does not dramatically improve performance as Page and Action cachings do. It is implemented with Action caching.
You need to insert expire_{page,action,fragment} calls normally in create, update, and destroy actions in order to delete caches. However, Cache sweeping (Sweepers) is an automatic mechanism which allows you to get around having a ton of expire_{page,action,fragment} calls in your code. Sweeper needs an "observe" that observes a model to be changed. Once you have a sweeper class, the sweeper has to be added to the controller that will use it.
Query caching is a Rails feature that caches the result set returned by each query. If Rails encounters the same query again during the current request, it will used the cached result set as opposed to running the query against the database.
Cache Stores
Caching data is stored at disk, memory, and DB.
1. ActiveSupport::Cache::MemoryStore: A cache store implementation which stores everything into memory in the same process.
2. ActiveSupport::Cache::FileStore: Cached data is stored on the disk. This is the default store and the default path for this store is: /tmp/cache.
3. ActiveSupport::Cache::DRbStore: Cached data is stored in a separate shared DRb process that all servers communicate with.
4. MemCached store: Works like DRbStore, but uses Danga's MemCache instead. Rails uses the bundled memcached-client gem by default. This is currently the most popular cache store for production websites. It also needs to run memcached server. We will use MemCached store here.
5. ActiveSupport::Cache::SynchronizedMemoryStore: Like ActiveSupport::Cache::MemoryStore but thread-safe.
6. ActiveSupport::Cache::CompressedMemCacheStore: Works just like the regular MemCacheStore but uses GZip to decompress/compress on read/write
7. Custom store: You can define your own cache store
We are using #4 MemCached store for both session and cache. In order to use it, memcached server should be run separately with rails server. In order to install memcached, you need to follow as:
MAC [4]
sudo port install memcached
Once you have memcache you'll want to start it running:
memcached -vv
The -vv puts memcache in Very Verbose mode so you get to see all the action. You'll run this as a daemon once you're ready to go for real (replace -vv with -d).
For Ruby we're using memcache-client and you'll need the gem:
sudo gem install memcache-client
Windows [5, 6]
1. Install MemCached (http://www.danga.com/memcached/). For windows download binaries and manually install. It is well explained in the site.
2. Install Memcached-Client
# gem install memcache-client
3. Start the memcached Server. It says Start the server from the Microsoft Management Console or by running the following command:
'c:\memcached\memcached.exe -d start'
However, it did not work on my Windows 7. You can go to the folder of memcached installed and just double-click on "memcached.exe" at window explorer. It'll run in port 11211. Besides, in the command prompt window, for example, at c:\memcached, you can type in
memcached -vv -P /tmp/memcached.pid
It will display cache object.
References
1. http://guides.rubyonrails.org/caching_with_rails.html
2. http://townx.org/rails_and_memcached
3. http://nubyonrails.com/articles/memcached-basics-for-rails
4. http://www.ridingtheclutch.com/2009/01/08/cache-anything-easily-with-rails-and-memcached.html
5. http://ratnaonrails.wordpress.com/2008/07/17/memcached-in-rails/
6. http://www.splinedancer.com/memcached-win32/
Page Caching
Action Caching
Fragment Caching
Sweepers
SQL Caching
Page caching is to cache a full page in a controller logic. It ignores parameters and good for stateless page not for stateful page that we used to have. Page caches are always stored on disk.
Action caching is to cache a full action response in a controller logic. Before caching, we can add before_filter in order to add more functions such as authentication.
Fragment Caching is to cache a part of a page in a view logic. It does not dramatically improve performance as Page and Action cachings do. It is implemented with Action caching.
You need to insert expire_{page,action,fragment} calls normally in create, update, and destroy actions in order to delete caches. However, Cache sweeping (Sweepers) is an automatic mechanism which allows you to get around having a ton of expire_{page,action,fragment} calls in your code. Sweeper needs an "observe" that observes a model to be changed. Once you have a sweeper class, the sweeper has to be added to the controller that will use it.
Query caching is a Rails feature that caches the result set returned by each query. If Rails encounters the same query again during the current request, it will used the cached result set as opposed to running the query against the database.
Cache Stores
Caching data is stored at disk, memory, and DB.
1. ActiveSupport::Cache::MemoryStore: A cache store implementation which stores everything into memory in the same process.
2. ActiveSupport::Cache::FileStore: Cached data is stored on the disk. This is the default store and the default path for this store is: /tmp/cache.
3. ActiveSupport::Cache::DRbStore: Cached data is stored in a separate shared DRb process that all servers communicate with.
4. MemCached store: Works like DRbStore, but uses Danga's MemCache instead. Rails uses the bundled memcached-client gem by default. This is currently the most popular cache store for production websites. It also needs to run memcached server. We will use MemCached store here.
5. ActiveSupport::Cache::SynchronizedMemoryStore: Like ActiveSupport::Cache::MemoryStore but thread-safe.
6. ActiveSupport::Cache::CompressedMemCacheStore: Works just like the regular MemCacheStore but uses GZip to decompress/compress on read/write
7. Custom store: You can define your own cache store
We are using #4 MemCached store for both session and cache. In order to use it, memcached server should be run separately with rails server. In order to install memcached, you need to follow as:
MAC [4]
sudo port install memcached
Once you have memcache you'll want to start it running:
memcached -vv
The -vv puts memcache in Very Verbose mode so you get to see all the action. You'll run this as a daemon once you're ready to go for real (replace -vv with -d).
For Ruby we're using memcache-client and you'll need the gem:
sudo gem install memcache-client
Windows [5, 6]
1. Install MemCached (http://www.danga.com/memcached/). For windows download binaries and manually install. It is well explained in the site.
2. Install Memcached-Client
# gem install memcache-client
3. Start the memcached Server. It says Start the server from the Microsoft Management Console or by running the following command:
'c:\memcached\memcached.exe -d start'
However, it did not work on my Windows 7. You can go to the folder of memcached installed and just double-click on "memcached.exe" at window explorer. It'll run in port 11211. Besides, in the command prompt window, for example, at c:\memcached, you can type in
memcached -vv -P /tmp/memcached.pid
It will display cache object.
References
1. http://guides.rubyonrails.org/caching_with_rails.html
2. http://townx.org/rails_and_memcached
3. http://nubyonrails.com/articles/memcached-basics-for-rails
4. http://www.ridingtheclutch.com/2009/01/08/cache-anything-easily-with-rails-and-memcached.html
5. http://ratnaonrails.wordpress.com/2008/07/17/memcached-in-rails/
6. http://www.splinedancer.com/memcached-win32/
Subscribe to:
Posts (Atom)