This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error Type : 1. Use "includes" instead of "joins" with kaminari pagination. | |
example : | |
books = Book.joins( :other_category ).where(['books.published_on is not null and other_categories.name like ?', "%#{category_name}%"]).order('books.title').page( page ).per( per ) | |
it makes sql for counting the record as : | |
SELECT COUNT(*) FROM `books` WHERE ( books.id IN (SELECT DISTINCT other_categories.book_id FROM other_categories WHERE other_categories.name LIKE '%Fiction%')) LIMIT 10 OFFSET 20 | |
This sql failed to return the count dues to limit and offset. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to setup netsed model in Rails 3 | |
======================================== | |
CREATE TABLE `books` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`title` varchar(255) DEFAULT NULL, | |
`description` text, | |
`imported_from` varchar(255) DEFAULT NULL, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'zip/zip' | |
def unzip_file (file, destination) | |
Zip::ZipFile.open(file) { |zip_file| | |
zip_file.each { |f| | |
f_path=File.join(destination, f.name) | |
FileUtils.mkdir_p(File.dirname(f_path)) | |
zip_file.extract(f, f_path) unless File.exist?(f_path) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://blog.wyeworks.com/2009/7/13/paperclip-file-rename | |
Paperclip.interpolates :default_image_type do |attachment, style| | |
attachment.instance.get_user_default_profile_image | |
end | |
Paperclip.interpolates :normalized_avatar_file_name do |attachment, style| | |
attachment.instance.normalized_avatar_file_name | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It works for pure text only. It will fail for html and url type of text. | |
# http://henrik.nyh.se/2007/03/ruby-wordwrap-method | |
def wrap_long_string(text,max_width = 20) | |
(text.length < max_width) ? | |
text : | |
text.scan(/.{1,#{max_width}}/).join("<wbr>") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install sphinx for Rails 3 | |
================================= | |
http://freelancing-god.github.com/ts/en/installing_sphinx.html | |
1) Download : http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz | |
2) ./configure (It will configure with mysql default) | |
3) make | |
4) sudo make install | |
5) goto (cd) rails project directory | |
6) bundle exec rake ts:index RAILS_ENV=staging |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://mathiasbynens.be/demo/url-regex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//using jquery date picker | |
function getPreviousDay(event){ | |
event.preventDefault(); | |
var currDate = $('#date_box').val(); | |
currDate = $.datepicker.parseDate('mm/dd', currDate); | |
var d = currDate.getDate(); | |
var m = currDate.getMonth(); | |
var y = currDate.getFullYear(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
svn checkout https://server.example.com/srv/svn/agaric myworkingcopyfolder | |
svn status | |
svn update | |
svn add yournewfilehere | |
svn add yournewdirectoryincludingfiles/ | |
svn commit -m "I made changes. Woohoo." files1 files2 | |
Use 'add' for only new file. | |
http://www.linuxfromscratch.org/blfs/edguide/chapter03.html#ch03-add |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XML parsing does not support entity. is XHTML entity. If we parse the html or xml or html as xml then you get "Undefined entity" error in firefox error console. To make it working use unicode of (non-breakibg space character)   or simply put space (" " or  ). | |
for example : | |
<div> hello I am going to break. If you are going to use xml parser :( </div> | |
Corrected as : | |
<div>   hello I am going to break. If you are going to use xml parser :( </div> |