Patch – URI not able to parse the url properly
module URI
def self.parse(uri)
uri = URI.encode(uri)
scheme, userinfo, host, port,
registry, path, opaque, query, fragment = self.split(uri)
if scheme && @@schemes.include?(scheme.upcase)
@@schemes[scheme.upcase].new(scheme, userinfo, host, port,
registry, path, opaque, query,
fragment)
else
Generic.new(scheme, userinfo, host, port,
registry, path, opaque, query,
fragment)
end
end
end
Patch to the TMail core classes in order to avoid errors in messages with bad encoding definition
module TMail
class Unquoter
class << self
def convert_to(text, to, from)
return text unless to && from
from.gsub!(‘ISO88′,’ISO-88′) #we found some strange cases in which the encoding was lacking the dash
from.gsub!(‘ks_c_5601-1987′,’euc-kr’) # ks_c_5601-1987 and euc-kr are different encodings and the second one is the referred one for e-mails #http://lists.kde.org/?l=kde-i18n-doc&m=100396886120761&w=2
text ? Iconv.conv(“#{to}//IGNORE//TRANSLIT”, from, text) : ” #the encoding is done with ignore and translit to fix as much errors as possible
rescue Iconv::IllegalSequence, Errno::EINVAL
# the ‘from’ parameter specifies a charset other than what the text
# actually is…not much we can do in this case but just return the
# unconverted text
#
# Ditto if either parameter represents an unknown charset (i.e X-UNKNOWN),
# and if the //IGNORE didn’t work fine
text
end
end
end
end
Tmail Issue – Patch fixing the bug in email encoding. Emails with multiple recipients were malformed having extra blank line between every 4-7 recipient addresses.
Solution:
module TMail
class Encoder
def puts_meta( str )
add_text str
end
end
end
Exception notification solution for rails 2.3
ERROR : `const_missing’: uninitialized constant ApplicationController::ExceptionNotification (NameError)
Installing “exception_notification” for Rails 2.3
script/plugin install git://github.com/rails/exception_notification.git -r 2-3-stable
ERROR: `gem_original_require’: no such file to load — action_dispatch (MissingSourceFile)
Change
ExceptionNotifier.exception_recipients = %w(your@emailaddress.com)
with
ExceptionNotification::Notifier.exception_recipients = %w(joe@schmoe.com bill@schmoe.com)
in environment.rb
Ajaxified Pagination with ‘will paginate’ plugin
We need to override the “page_link_or_span”. Just add the following method to
vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb
def page_link_or_span(page, span_class, text = nil)
text ||= page.to_s
classnames = Array[*span_class]
if page and page != current_page
if @options[:update]
@template.link_to_remote text, :update => @options[:update], :url =>url_for(page)
else
@template.link_to_remote text, :url =>url_for(page)
#@template.link_to text, url_for(page), :rel => rel_value(page), :class => classnames[1]
end
else
@template.content_tag :span, text, :class => classnames.join(‘ ‘)
end
end
View
<%= will_paginate @messages,:params=>{:controller=>’messages’,:action=>’show_folder’,:id => @msg_folder.id},:container => false %>
Displaying “file download dialog box” in Rails
Rails comes with “send_file()” function which is used to send the contents of an open file over an existing socket connection.
View:
<%=link_to “view”, {:action => “download”,:id=>doc.id}%>
Controller:
def download
@document = Document.find(params[:id])
@filepath = @document.full_filename
send_file(@filepath,
:disposition => ‘attachment’,
:encoding => ‘utf8′,
:type => ‘application/octet-stream’)
end
So easy
ssh git@github.com Agent admitted failure to sign using the key. Permission denied (publickey)
You might need to ssh-add ~/.ssh/id_rsa also, if the system isn’t doing it for you automatically.
Override automatic updated_at in Rails
User.record_timestamps=false
User.first.update_attributes(:updated_at => 6.years.ago)
User.record_timestamps=true
‘like’ in Rails
items = Item.find(:all, :conditions => ["name like ?", "%" like "%"])
