Wednesday, May 30, 2012
Tuesday, May 29, 2012
Rails 3 jquery_ujs - link_to :remote triggers two ajax calls on click
Issue: link_to :remote triggers two ajax calls on click in rails 3+
Solution: Make sure you have not included //= require jquery_ujs in the application.js file in assets since jquery-rails already handles this in rails 3.1
courtesy: link
Solution: Make sure you have not included //= require jquery_ujs in the application.js file in assets since jquery-rails already handles this in rails 3.1
courtesy: link
Rails 3 - Installing pg with native extensions
Installing pg (0.13.2) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
Solution:
sudo apt-get install libpq-dev
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
Solution:
sudo apt-get install libpq-dev
Tuesday, May 15, 2012
Invalid CSS issue on RAILS_ENV=production bundle exec rake --trace assets:precompile
1)Remove all the requires in app/assets/application.css file
2)Now add config.assets.precompile = ['*.css'] in application.rb file
3)Now run RAILS_ENV=production bundle exec rake --trace assets:precompile which will help to trace the exact files where the css issue exist and then fix all the issues mentioned in the css files
4) When all the css issues are fixed then remove config.assets.precompile = ['*.css'] and then revert any requires in your application.css which was present earlier and run the RAILS_ENV=production bundle exec rake --trace assets:precompile again. This should fix the issue.
2)Now add config.assets.precompile = ['*.css'] in application.rb file
3)Now run RAILS_ENV=production bundle exec rake --trace assets:precompile which will help to trace the exact files where the css issue exist and then fix all the issues mentioned in the css files
4) When all the css issues are fixed then remove config.assets.precompile = ['*.css'] and then revert any requires in your application.css which was present earlier and run the RAILS_ENV=production bundle exec rake --trace assets:precompile again. This should fix the issue.
Connecting datacard on Ubuntu 11
1) Go to -Dash home >> Network Connections
2) Select Mobile Broadband and click on "Add"
3) Select your mobile connection in dropdown >> "Continue"
4) Select your country and click on "Continue"
4) Select your service provide and click on "Continue"
5) Select your plan and click on "Apply" >> "Save"
2) Select Mobile Broadband and click on "Add"
3) Select your mobile connection in dropdown >> "Continue"
4) Select your country and click on "Continue"
4) Select your service provide and click on "Continue"
5) Select your plan and click on "Apply" >> "Save"
Tuesday, May 8, 2012
Using bundle exec in Rails 3
1)bundle exec
executes a command in the context of your bundle.That means it uses the gems specified in your Gemfile. Much of the time, running
bundle exec rake foo
has the same results as if you just ran rake foo
,
especially if you have the same gems installed systemwide as in your
Gemfile. However, some applications may specify different versions of
gems than the ones you have installed systemwide, and may want those
exact gems and versions to be able to run correctly. If you just run
without bundle exec
, you may get some weird errors.Using
bundle exec
guarantees that the program is run
with the environment specified in the gemfile, which hopefully means it
is the environment that the creators of the program want it to be run
in, which hopefully means it should run correctly no matter what weird
setup you have on your computer.It basically standardizes the environment under which the program is run. This helps avoid version hell and makes life much easier.
See http://gembundler.com/man/bundle-exec.1.html for more info.
Friday, May 4, 2012
Installing Chrome on Ubuntu
Run the following commands in terminal:
1) wget -q -O -
https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key
add -
2) sudo sh -c 'echo "deb
http://dl.google.com/linux/chrome/deb/ stable main" >>
/etc/apt/sources.list.d/google.list'
3) sudo apt-get update
4) sudo apt-get install
google-chrome-stable
Tuesday, April 24, 2012
Rails 3 Ubuntu 11.10 Installing nokogiri (1.5.2) with native extensions
Issue:
Using bundler (1.1.3)
Installing nokogiri (1.5.2) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-1.9.2-p318/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
--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=/home/ganesh/.rvm/rubies/ruby-1.9.2-p318/bin/ruby
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/lib
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
--with-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
Fix:
Do the following:
1) sudo apt-get install libxml2-dev
2) sudo apt-get install libxslt1-dev
and then
bundle install
Using bundler (1.1.3)
Installing nokogiri (1.5.2) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-1.9.2-p318/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
--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=/home/ganesh/.rvm/rubies/ruby-1.9.2-p318/bin/ruby
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/lib
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
--with-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
Fix:
Do the following:
1) sudo apt-get install libxml2-dev
2) sudo apt-get install libxslt1-dev
and then
bundle install
Thursday, March 22, 2012
Update DelayedJob run_at to change daily emails send time
Below is just a sample code.
1) Create a table to track delayed jobs
class CreateTrackDelayedJobs < ActiveRecord::Migration
def self.up
create_table :track_delayed_jobs do |t|
t.integer :delayed_job_id
t.integer :user_id
t.integer :item_id
t.timestamps
end
end
def self.down
drop_table :track_delayed_jobs
end
end
2)Sample code to send daily news letters
a) Add a rake task which can be run everyday
task :send_news_letters => :environment do
items = Item.all
items.each do |current_item|
send_time = Time.zone.local(Date.today.year, Date.today.month, Date.today.day, hours, minutes)
NewsLetter.send_at(send_time, :send_digest, curent_item.id)
end
b)
class NewsLetter
def self.send_in(time, method, *args)
send_at time.from_now, method, *args
end
def self.send_at(time, method, *args)
dj = Delayed::Job.enqueue Delayed::PerformableMethod.new(self, method.to_sym, args), 0, time
track_dj = TrackDelayedJob.where("item_id = ?",args[0]).first
if track_dj.nil?
TrackDelayedJob.create(:delayed_job_id => dj.id, :item_id => args[0])
else
old_dj = Delayed::Job.find_by_id(track_dj.delayed_job_id)
old_dj.destroy unless old_dj.nil?
track_dj.update_attribute(:delayed_job_id, dj.id)
end
end
def self.send_digest(item_id)
#write your code to send digest.
end
end
c) When you want to update already set delayed job then
NewsLetter.update_delayed_job_time(item_id, time)
add this in NewsLetter class
def self.set_delayed_job_time(item_id, time)
track_dj = TrackDelayedJob.where("item_id = ?", item_id).first
dj = Delayed::Job.find_by_id(track_dj.delayed_job_id) unless track_dj.nil?
unless dj.nil?
#below code is required in case you want to convert hours and minutes
# time = "#{Date.today} #{hours}:#{minutes}".to_time
dj.run_at = time
dj.save
end
end
end
1) Create a table to track delayed jobs
class CreateTrackDelayedJobs < ActiveRecord::Migration
def self.up
create_table :track_delayed_jobs do |t|
t.integer :delayed_job_id
t.integer :user_id
t.integer :item_id
t.timestamps
end
end
def self.down
drop_table :track_delayed_jobs
end
end
2)Sample code to send daily news letters
a) Add a rake task which can be run everyday
task :send_news_letters => :environment do
items = Item.all
items.each do |current_item|
send_time = Time.zone.local(Date.today.year, Date.today.month, Date.today.day, hours, minutes)
NewsLetter.send_at(send_time, :send_digest, curent_item.id)
end
b)
class NewsLetter
def self.send_in(time, method, *args)
send_at time.from_now, method, *args
end
def self.send_at(time, method, *args)
dj = Delayed::Job.enqueue Delayed::PerformableMethod.new(self, method.to_sym, args), 0, time
track_dj = TrackDelayedJob.where("item_id = ?",args[0]).first
if track_dj.nil?
TrackDelayedJob.create(:delayed_job_id => dj.id, :item_id => args[0])
else
old_dj = Delayed::Job.find_by_id(track_dj.delayed_job_id)
old_dj.destroy unless old_dj.nil?
track_dj.update_attribute(:delayed_job_id, dj.id)
end
end
def self.send_digest(item_id)
#write your code to send digest.
end
end
c) When you want to update already set delayed job then
NewsLetter.update_delayed_job_time(item_id, time)
add this in NewsLetter class
def self.set_delayed_job_time(item_id, time)
track_dj = TrackDelayedJob.where("item_id = ?", item_id).first
dj = Delayed::Job.find_by_id(track_dj.delayed_job_id) unless track_dj.nil?
unless dj.nil?
#below code is required in case you want to convert hours and minutes
# time = "#{Date.today} #{hours}:#{minutes}".to_time
dj.run_at = time
dj.save
end
end
end
Saturday, March 17, 2012
Rails - Install and starting memcached on windows
1) Download Memcached for windows and extract it.
2) Open the command prompt as administrator and then run the command (assuming
your memcached is in c:\memcached)
c:\memcached\memcached.exe -d install
(Incase you get the below error:
C:\Windows\System32>c:\memcached\memcached.exe -d install
failed to install service or service already installed
Please make sure your are running the command prompt as administrator
start>command prompt> right click it and run as administrator.)
3) Start the server by:
C:\Windows\system32>net start "memcached Server"
The memcached Server service is starting.
The memcached Server service was started successfully.
2) Open the command prompt as administrator and then run the command (assuming
your memcached is in c:\memcached)
c:\memcached\memcached.exe -d install
(Incase you get the below error:
C:\Windows\System32>c:\memcached\memcached.exe -d install
failed to install service or service already installed
Please make sure your are running the command prompt as administrator
start>command prompt> right click it and run as administrator.)
3) Start the server by:
C:\Windows\system32>net start "memcached Server"
The memcached Server service is starting.
The memcached Server service was started successfully.
Saturday, March 10, 2012
Rails Resque + RuntimeError at /resque/overview ERR unknown command 'server' issue
Issue: RuntimeError at /resque/overview ERR unknown command 'server' on windows at localhost:3000/overview
Fix: Just do a 'gem cleanup resque' to remove older versions of resque and then 'bundle update'.
Fix: Just do a 'gem cleanup resque' to remove older versions of resque and then 'bundle update'.
Friday, March 2, 2012
Rails 3 Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
Issue:
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/home/user/.rvm/gems/ruby-1.9.2-head/gems/execjs-1.2.6/lib/execjs/runtimes.rb:46:in `autodetect'
/home/user/.rvm/gems/ruby-1.9.2-head/gems/execjs-1.2.6/lib/execjs.rb:5:in `'
/home/user/.rvm/gems/ruby-1.9.2-head/gems/execjs-1.2.6/lib/execjs.rb:4:in `'
/home/user/.rvm/gems/ruby-1.9.2-head/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
Fix:
Add gem ‘therubyracer’ into Gemfile and then do a 'bundle install'
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/home/user/.rvm/gems/ruby-1.9.2-head/gems/execjs-1.2.6/lib/execjs/runtimes.rb:46:in `autodetect'
/home/user/.rvm/gems/ruby-1.9.2-head/gems/execjs-1.2.6/lib/execjs.rb:5:in `
/home/user/.rvm/gems/ruby-1.9.2-head/gems/execjs-1.2.6/lib/execjs.rb:4:in `
/home/user/.rvm/gems/ruby-1.9.2-head/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
Fix:
Add gem ‘therubyracer’ into Gemfile and then do a 'bundle install'
Thursday, March 1, 2012
Running a specific migration file
1) Incase you want to run migration from a particular file then
rails console>> require "db/migrate/20110210070832_create_companies.rb"
>> CreateCompanies.up
other ways:
rake db:migrate:up VERSION=my_version
rake db:migrate:down VERSION=my_version
Thursday, February 23, 2012
Installing mysql2 gem on Ubuntu
Issue:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** 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
--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=/home/user/.rvm/rubies/ruby-1.9.2-head/bin/ruby
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.2-head/gems/mysql2-0.3.7 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.2-head/gems/mysql2-0.3.7/ext/mysql2/gem_make.out
An error occured while installing mysql2 (0.3.7), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.7'` succeeds before bundling.
Fix:
sudo apt-get install libmysqlclient-dev
rvm 1.9.2-head gem install mysql2
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** 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
--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=/home/user/.rvm/rubies/ruby-1.9.2-head/bin/ruby
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.2-head/gems/mysql2-0.3.7 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.2-head/gems/mysql2-0.3.7/ext/mysql2/gem_make.out
An error occured while installing mysql2 (0.3.7), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.7'` succeeds before bundling.
Fix:
sudo apt-get install libmysqlclient-dev
rvm 1.9.2-head gem install mysql2
Monday, February 20, 2012
Sunspot issue - You need a Java Runtime Environment to run the Solr server
C:\Users\project1>rake sunspot:solr:run --trace
DEPRECATED! (configure_from_yaml) Please stop using YAML and use Ruby instead. T
his method will be removed in 2.9.
** Invoke sunspot:solr:run (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sunspot:solr:run
The syntax of the command is incorrect.
rake aborted!
You need a Java Runtime Environment to run the Solr server
Fix:
Modify C:\Ruby192\lib\ruby\gems\1.9.1\gems\sunspot_solr-1.3.0\lib\sunspot\solr\java.rb file with
module Sunspot
module Solr
module Java
def self.installed?
true
end
end
end
end
Also make sure your gemfile has:
gem 'sunspot_rails'
# This is an optional packaged Solr:
group :test, :development do
gem 'sunspot_solr'
end
Reference Links:
https://github.com/sunspot/sunspot/issues/147
DEPRECATED! (configure_from_yaml) Please stop using YAML and use Ruby instead. T
his method will be removed in 2.9.
** Invoke sunspot:solr:run (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sunspot:solr:run
The syntax of the command is incorrect.
rake aborted!
You need a Java Runtime Environment to run the Solr server
Fix:
Modify C:\Ruby192\lib\ruby\gems\1.9.1\gems\sunspot_solr-1.3.0\lib\sunspot\solr\java.rb file with
module Sunspot
module Solr
module Java
def self.installed?
true
end
end
end
end
Also make sure your gemfile has:
gem 'sunspot_rails'
# This is an optional packaged Solr:
group :test, :development do
gem 'sunspot_solr'
end
Reference Links:
https://github.com/sunspot/sunspot/issues/147
Monday, February 13, 2012
Useful links to install redis on windows
Download and install:
https://github.com/rgl/redis/downloads
References:
https://github.com/dmajkic/redis http://redis.io/documentation
You may need this as well:
http://www.mingw.org/wiki/Getting_Started http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20111118/
https://github.com/rgl/redis/downloads
References:
https://github.com/dmajkic/redis http://redis.io/documentation
You may need this as well:
http://www.mingw.org/wiki/Getting_Started http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20111118/
Subscribe to:
Posts (Atom)