Posts

Auto Complete Text Box in Rails

Image
Found an Awesome plugin https://github.com/rails/auto_complete for doing this and i made it in 5-10 mins. Install plugin : ruby script/plugin install git://github.com/rails/auto_complete.git Use in HTML for Text field: <%= text_field_with_auto_complete 'phonenumber', 'to',{}, :skip_style => false %> Controller : skip_before_filter :verify_authenticity_token, :only => [:auto_complete_for_phonenumber_to] def auto_complete_for_phonenumber_to phonenumber = params[:phonenumber][:to] @phones = CustomerPhone.phonenumber_search(phonenumber) render :partial => 'phonenumbers' end Search Query in model: def self.phonenumber_search(keyword) find(:all, :conditions=>["phonenumber like ?", "%#{keyword}%"]) end View : Create Partial : "_phone_number.html.erb" <%= auto_complete_result @phones, :phonenumber %> Restart your Server & Search. It works. Note : If you get undefined method...

HTML stripping, Truncating string in Ruby, Rails

For Truncating String I have used 'truncate' rails helper method. limiting to 10 characters truncate("im srikanth glad to meet you", 10) >> "im srik..." For HTML stripping, I have used gsub.. str.gsub(/ ]*>/, "")

Weekday or not..

You can Use this , def weekday? (1..5).include?(wday) end check .. d = Date.today => Mon, 04 Oct 2010 d.weekday? => true d = Date.today - 1 => Sun, 03 Oct 2010 d.weekday? => false

Rails find_by_sql returns object ??

you can use this, ActiveRecord::Base.connection.select_value("sql query")

Installing pauldix-feedzirra

Hi when i tried to install pauldix-feedzirra, i got the below error. sudo gem install pauldix-feedzirra Building native extensions. This could take a while... ERROR: Error installing pauldix-feedzirra: ERROR: Failed to build gem native extension. /usr/local/bin/ruby extconf.rb checking for libxml/parser.h... yes checking for libxslt/xslt.h... no ----- libxslt is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies. ----- *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/local/bin/ruby --with-zlib-dir --without-zlib-dir...

Problems in Installing Curb in ubuntu

Just install the below lib files, sudo apt-get install libcurl3 libcurl3-gnutls libcurl4-openssl-dev & then, sudo gem install curb It works! -- source - http://axonflux.com/curb-install-problems-on-ubunt

Sending HTML mail in rails

Hi pals, If all the mails that you send are in HTML format. its simple. Specify this line in environment.rb ActionMailer::Base.default_content_type = "text/html" If only one action has to be in HTML mail, specify 'content_type' in that action. content_type "text/html" example, def signup_notification(recipient) recipients recipient.email_address_with_name subject "New account information" from "system@example.com" content_type "text/html" end cheers, Sri