Ripan – 'Ruby on Rails' enthusiastic


Moped::Errors::ConnectionFailure: Could not connect to a primary node for replica set <Moped::Cluster nodes=[]>

Posted in Uncategorized by Ripan on September 30, 2013

 

  1. brew unlink mongodb
  2. brew install mongodb
  3. ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents (To have launchd start mongodb at login)
  4. launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist (Then to load mongodb now)

You are ready to go …now :)

Setting up Mongo for rails 3.2.X, Ruby 1.9.3

Posted in Uncategorized by Ripan on September 30, 2013
  1. Install MongoDB with Package Management.

    brew install mongodb
  2. rails new app_name –skip-active-record
  3. Simply add Mongoid to your Gemfile.     gem “mongoid”, “~> 3.0.0″        
  4. rails g mongoid:config

Patch – URI not able to parse the url properly

Posted in Ruby On Rails by Ripan on May 22, 2011

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

Posted in Ruby On Rails by Ripan on May 22, 2011

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.

Posted in Ruby On Rails by Ripan on May 22, 2011

Solution:

module TMail
class Encoder
def puts_meta( str )
add_text str
end
end
end

Exception notification solution for rails 2.3

Posted in Ruby On Rails by Ripan on March 21, 2011

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

Posted in Ruby On Rails by Ripan on July 5, 2010

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

Posted in Ruby On Rails by Ripan on April 13, 2010

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 :)

download dialog

ssh git@github.com Agent admitted failure to sign using the key. Permission denied (publickey)

Posted in Uncategorized by Ripan on April 1, 2010

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

Posted in Ruby On Rails by Ripan on February 7, 2010

User.record_timestamps=false
User.first.update_attributes(:updated_at => 6.years.ago)
User.record_timestamps=true

Next Page »

Follow

Get every new post delivered to your Inbox.