Another installment of How iPhone to Twitter/Facebook/MySpace/Wordpress/Xanga/LiVEJOURNAL/Blogger/TypePad/VOX.
Blogged with MessageDance using YouTube
Another installment of How iPhone to Twitter/Facebook/MySpace/Wordpress/Xanga/LiVEJOURNAL/Blogger/TypePad/VOX.
Blogged with MessageDance using YouTube
def get_ruby_array_from_java_array_list(java_array_list)
java_array_list[1, java_array_list.length-2].split(", ")
end
Blogged with MessageDance using Gmail
This one is for Rails 1.1.6. Currently auto_link_urls helper method in text_helper.rb file works well with most of the url’s. It fails to auto link when there are special characters like ~/@/# etc. So here is the quick fix
([\w]+:?[=?&\/.-]?)* # url segment
to
([\w~,@#\$]+:?[=?&\/.-]?)* # url segment, added support for ~/,/@/#/$ in urls
Just adding special characters to the regex expression works. BTW I tried porting Rails 1.2 text helper code (which looks a lot different than this and it does not work).
For some reason I like to work with older versions Rails :). This paginating_find plugin is written to use newer version of Rails’s alias method chaning, which will not work with Rails 1.1.6. If you install paginating_find in your vendors folder and start your server you will get error something like this
../vendor/plugins/paginating_find/lib/paginating_find.rb:11:in `included’: undefined method `alias_method_chain’ for #<Class:ActiveRecord::Base> (NoMethodError)
from /Users/railsapp/config/../vendor/plugins/paginating_find/lib/paginating_find.rb:8:in `class_eval’
from /Users/railsapp/config/../vendor/plugins/paginating_find/lib/paginating_find.rb:8:in `included’
from /Users/railsapp/config/../vendor/plugins/paginating_find/init.rb:1:in `include’
So here it is My tweak to make paginating_find plugin work with Rails 1.1.6 (This assumes you have followed the plugin install steps from Alex’s blog ).
Just replace alias_method_chain line in paginating_find.rb file with following
self.send :alias_method, :find_without_pagination, :find
self.send :alias_method, :find, :find_with_pagination
This technique works with any alias_method_chain backward compatibility to older version of Rails. I have posted similar post for attachment_fu make it work with Rails 1.1.6 here
Hope that helps.
I was using acts_as_attachment plugin for file upload and I wanted to get the files to Amazon S3. Unfortunately acts_as_attachment does not do that and attachment_fu does (both of these great plugins are written by Rick Olsen) and attchment_fu needs Rails 1.2 and higher. I have a limitation of using Rails 1.1.6. So made attachment_fu work with Rails 1.1.6. Not a whole lot of changes , should take less that 3 mins. So this is what you do
base.alias_method_chain :process_attachment, :processing
with
base.send :alias_method, :process_attachment_without_processing, :process_attachment
base.send :alias_method, :process_attachment, :process_attachment_with_processing
(The reason it needed Rails 1.2 in first place because of base.alias_method_chain call which is introduced in Rails 1.2. So It was just a matter of replacing that with the Rails 1.1.6 equivalent). Similarly you can go do the same above change to other 2 processors as well (image_science and mini_magick)
def find_or_initialize_thumbnail(file_name_suffix)
respond_to?(:parent_id) ?
thumbnail_class.find_or_initialize_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) :
thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
end
with
def find_or_initialize_thumbnail(file_name_suffix) respond_to?(:parent_id) ?
thumbnail_class.find_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) ||
thumbnail_class.new(:thumbnail=>file_name_suffix.to_s, :parent_id=>id) :
thumbnail_class.new(:thumbnail=>file_name_suffix.to_s)
end
Thats it you should be flyig with this change on Rails 1.1.6.
You must have seen http://twitter.com/legalizenet where legalizenet is my screen name and I get a first context on twitter.com like every user. Its just one line of definition in the Rails routes.rb file. Just add following map.connect ‘:screen_name’, :controller => “<somecontroller>”, :action=> “<someaction>”(Note: replace <somecontroller> with right controller name and <someaction> with a right action in that controller)e.g it might look like map.connect ‘:screen_name’, :controller => “profile”, :action=> “home”This will tell rails engine , whenever there is a url like http://<hostname>/<screen_name> send request to profile_controller.rb’s “home” action. and then in home action method just do followingparams[:screen_name] and process it accordingly.Sweet isn’t it?
You will possibly be seeing this error when you use acts_as_attachment for thumbnailing.
undefined method `find_or_initialize_by_thumbnail_and_parent’
Basically acts_as_attachment is trying to use dynamic finders ( Good article on that is here ) to find and create new object if it is not found. Developers use acts_a_attachment ( instead of attachument_fu; successor of acts_a_attachment works only Rails 1.2 onwards) because it works with older version of Rails (1.1.6) and when you execute thumbnailing you get above message and the reason the dynamic method find_or_initialize_by_thumbnail_and_parent that internally calls find_or_initialize which is available in Edge rails onwards and Rails 1.1.6 does not have that. So kinda defeats the purpose of using acts_a_attachment for Rails 1.1.6.
In any case don’t be disappointed and here is the fix ,so you can use everything as it is. Go to your vendors/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/instance_methods.rb and look for method find_or_initialize_thumbnail , you need to patch this method to make it work with Rails 1.1.6 ( basically find and create new object seperately)
Replace following
def find_or_initialize_thumbnail(file_name_suffix) respond_to?(:parent_id) ? thumbnail_class.find_or_initialize_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) : thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
end
with
def find_or_initialize_thumbnail(file_name_suffix) respond_to?(:parent_id) ? thumbnail_class.find_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) ||thumbnail_class.new(:thumbnail=>file_name_suffix.to_s,:parent_id=>id) :thumbnail_class.new(:thumbnail=>file_name_suffix.to_s) end
This should do the trick.
Lot of times we run into a situation, where we do not have sendmail available to test emails because of you are not working on a unix environment, which has sendmail support. The only other option you are left with is SMTP email relay and it gets hard again when you do not have SMTP server available. Best option is to use popular email applications like Gmail to send emails. Gmail will not let you send email directly by specifying basic SMTP auth settings in your rails application. It needs to be more secured.
Following blog post from Anatol Pomozov makes it as a slam dunk. This enables all gmailers to have a capability to send emails from their Rails application.
Another alternative is to setup your own SMTP server. You can try msmtp
This error is very interesting and can possibly waste a lot of time , if you do not know the main reason behind it. I’m sharing this here, so that all those programmers who will possibly run into this issue, Google it for solution and will eventually land on my blog post and hopefully I will save someones day.
Issue is : TypeError (singleton can’t be dumped): Now when you are running a Rails app, this will be dumped into your development.log or production.log depending on your application environment.
Full trace will look something like this
/usr/local/lib/ruby/1.8/pstore
/usr/local/lib/ruby/1.8/pstore
/usr/local/lib/ruby/1.8/pstore
/usr/local/lib/ruby/1.8/cgi
/usr/local/lib/ruby/1.8/cgi
/usr/local/lib/ruby/1.8/cgi
.//vendor/rails/actionpack/lib
Root cause: In your Ruby/Rails code you are trying to add a singleton class in the session, which is against the compatibility rules. So look for pure singleton class or Modules that’s getting added to the rails session.
Solution: Have a class inside the Singelton class which will hold the data that you want to store in session and add that to your session. This will work.
We are running into quite a few issues with latest Rails version 1.2 starting with Theme generator complaining about “named_route” , following is the exception that we get
=> Booting WEBrick…
./script/../config/../vendor/plugins/theme_support/lib/patches/routeset_ex.rb:26:in `create_theme_routes’: undefined method `named_route’ for #<actioncontroller::routing::routeset:0xb7d34690> (NoMethodError)
from script/../config/../vendor/plugins/theme_support/lib/patches/routeset_ex.rb:13:in `draw’
Reason is Theme generator is using its own routes extension for its custom routes and as per Rails 1.2 release , Routes section).
So meanwhile we figure out how to fix this or Theme generator comes with fix for Rails 1.2, Following is the fix that you can do
# Lets freeze the Rails for Ajuby release by running following command
> rake rails:freeze:edge TAG=rel_1-1-6
This will take rails 1.1.6 and make rails available within Ajuby framework, (We will eventually go this route. Every release will be bundled with Rails , so one less thing to worry with)
# After above step successfully complete, start the WEBrick and see if you run into any error , if yes possibly you would not have Activerecord core frozen properly. Not sure whether its a bug in the rake process. If you see this error like undefined method “deprecate” or #<Class:……
Copy activerecord/lib directory from your installed Rails (wherever you have installed rails version 1.1.6 before above freeze process) to <ajubyhome>/vendor/rails/activerecord/lib directory