Retrieve SQL query in Rails 2.x
The method is construct_finder_sql(options) (lib/active_record/base.rb:1681) you will have to use send because it is private.
sql = Item.send :construct_finder_sql, :select => :all, :include => [:categories, :prices], :conditions => conditions
sql = ActionType.send :construct_finder_sql, :select => 'hosted, top_action_type, count(*) as count', :group => 'hosted, top_action_type'
Related cards:
include and extend in ruby
The extend method will mix a module’s methods at the class level.
On the other hand, the include method will mix a module’s methods at the instance level, meaning the methods will become instance methods of the class.
module Stringify
# R...
Adobe flash player installation in ubuntu chromium browser
For Chromium browser versions greater than 34, to use flash one must install Pepper flash.
For Ubuntu 14.04 or newer, run
sudo apt-get install pepperflashplugin-nonfree
sudo update-pepperflashplugin-nonfree --status
# to see what version of...
Abstract classes in rails
class AbstractModel < ActiveRecord::Base
self.abstract_class = true
end
class Foo < AbstractModel
end
class Bar < AbstractModel
end
Foo and Bar both inherit properties and methods of the Abstract Model while being in separate tables...
Adobe flash player installation in Ubuntu
This is to install adobe flash player in Ubuntu 14.04 or higher. This works for Firefox browser.
If you have a 32-bit OS, run
sudo apt-get update
sudo apt-get install flashplugin-installer
Make sure each of the commands executed success...
Check if package is installed in linux
To check if a given package is installed in Debian / Ubuntu, type
dpkg -s <package-name>
To get a neater output use dpkg-query which accepts wildcards as well.
dpkg-query -l <package-name>
In Redhat / Fedora / CentOS use the foll...
Prepend filters in rails
prepend_before_filter and append_before_filter are almost the same.
They differ only in precedence. Prepend filters have higher precedence over append filters.
before_filter is an alias to append_before_filter
class MyController < ActionCon...
deploying wordpress blog in rails application
1.First of all make sure that your server can parse both php and rails application.
-
Make a blog directory in side the public folder of rails application.
-
Deploy all WordPress content inside blog directory.
-
Configure your database conne...
Isues w/ caching in Incognito mode
I've noticed that Incognito mode retain cache from the previous session, it just don't collect any new cache while in incognito.
I usually clear the cache/cookies then go into incognito, or run a different browser profile, or a different browser ...
calling super in initialize
class Person
def initialize(name)
@name = name
end
end
class Employee < Person
end
emp = Employee.new # throws error wrong number of arguments
emp = Employee.new("foo") # parent class initialize method is called
cla...
difference between attr_accessor and initialize
attr_accessor is used to create setter and getter methods for instance variables so that they can be accessed outside the class. initialize is the special method in ruby that gets called when an object is instantiated.
class Birthday
attr_ac...