- Login to the server ssh user@ip
- Find access.log and error.log (Present in /var/log folder in my case or use the command "locate error.log" and "locate access.log" to search for the file)
- cd /var/log
- sudo rm yourwebsite.com-access.log
- sudo rm yourwebsite.com-error.log
- Restart using the command sudo service httpd restart
- Next restart servers (touch tmp/restart.txt)
Friday, July 31, 2015
Ruby on Rails - How to clear apache logs from server
Thursday, July 2, 2015
Error intalling node package manager npm before trying to install bower
Article written by Ganesh Prasad
Senior RoR Developer
Before installing Bower, which is a JavaScript command-line application, we need to setup npm (Node Package Manager)
If you already have old version installed then installing bower will throw following errors.
npm install -g bower
npm http GET http://registry.npmjs.org/bower
npm http 304 http://registry.npmjs.org/bower
npm ERR! Error: No compatible version found: bower
npm ERR! No valid targets found.
npm ERR! Perhaps not compatible with your version of node?
npm ERR! at installTargetsError (/usr/share/npm/lib/cache.js:488:10)
npm ERR! at next_ (/usr/share/npm/lib/cache.js:438:17)
npm ERR! at next (/usr/share/npm/lib/cache.js:415:44)
npm ERR! at /usr/share/npm/lib/cache.js:408:5
npm ERR! at saved (/usr/share/npm/lib/utils/npm-registry-client/get.js:147:7)
npm ERR! at Object.oncomplete (/usr/lib/nodejs/graceful-fs.js:230:7)
npm ERR! You may report this log at:
npm ERR!
npm ERR! or use
npm ERR! reportbug --attach /home/ganesh/npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.2.0-53-generic-pae
npm ERR! command "node" "/usr/bin/npm" "install" "-g" "bower"
npm ERR! cwd /home/ganesh
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! message No compatible version found: bower
npm ERR! message No valid targets found.
npm ERR! message Perhaps not compatible with your version of node?
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ganesh/npm-debug.log
npm not ok
If you already have old version installed then installing bower will throw following errors.
npm install -g bower
npm http GET http://registry.npmjs.org/bower
npm http 304 http://registry.npmjs.org/bower
npm ERR! Error: No compatible version found: bower
npm ERR! No valid targets found.
npm ERR! Perhaps not compatible with your version of node?
npm ERR! at installTargetsError (/usr/share/npm/lib/cache.js:488:10)
npm ERR! at next_ (/usr/share/npm/lib/cache.js:438:17)
npm ERR! at next (/usr/share/npm/lib/cache.js:415:44)
npm ERR! at /usr/share/npm/lib/cache.js:408:5
npm ERR! at saved (/usr/share/npm/lib/utils/npm-registry-client/get.js:147:7)
npm ERR! at Object.oncomplete (/usr/lib/nodejs/graceful-fs.js:230:7)
npm ERR! You may report this log at:
npm ERR!
npm ERR! or use
npm ERR! reportbug --attach /home/ganesh/npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.2.0-53-generic-pae
npm ERR! command "node" "/usr/bin/npm" "install" "-g" "bower"
npm ERR! cwd /home/ganesh
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! message No compatible version found: bower
npm ERR! message No valid targets found.
npm ERR! message Perhaps not compatible with your version of node?
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ganesh/npm-debug.log
npm not ok
Solution:
1) To fix the issue first uninstall the older version of npm (nodejs) packages that are already installed using the following command
sudo apt-get purge nodejs npm
2) Next install node js using the following command.
curl -L https://raw.github.com/midnightcodr/rpi_node_install/master/setup.sh | bash -s 0.10.24
3) Now that you have installed node js successfully, then install npm using the following command.
sudo apt-get install npm
4) Next you can install bower with the help of npm using the following command.
sudo npm install -g bower
Friday, March 21, 2014
Paperclip gem amazon s3 path .exists? throwing timeout error
Faced an issue where amazon s3 path was showing correctly but then when we try object.image.exists? then it threw
AWS::S3::Errors::RequestTimeout error
The issue got fixed after paperclip gem was upgraded to version 3.0.2
Reference links:
https://github.com/thoughtbot/paperclip/issues/751
Wednesday, March 5, 2014
Devise redirect to another subdomain without login
Devise gem redirect to another subdomain without login
Set the domain in initializers/session_store.rb
For example.
App::Application.config.session_store :cookie_store, key: '_play_cricket_session', domain: ".lvh.me"
App::Application.config.session_store :cookie_store, key: '_play_cricket_session', domain: ".website.com"
Set the domain in initializers/session_store.rb
For example.
App::Application.config.session_store :cookie_store, key: '_play_cricket_session', domain: ".lvh.me"
App::Application.config.session_store :cookie_store, key: '_play_cricket_session', domain: ".website.com"
Tuesday, April 16, 2013
Combining many rake tasks into one
namespace :playcricket do
desc 'build legacy data to new'
task :rebuild_database => ["playcricket:sample1", "playcricket:sample2", "playcricket:sample3"]
desc "first sample task"
task :sample1 => :environment do
puts "sample1 executed"
end
desc "second sample task"
task :sample2 => :environment do
puts "sample2 executed"
end
desc "call another rake task with arguments"
task :sample3 => :environment do
puts "sample3 executed"
Rake::Task["playcricket:sample4"].invoke("333")
end
desc "rake task with argument"
# => sample rake playcricket:sample4["767"]
task :sample4, [:sg_group_id] => :environment do |t, args|
puts "Migrating Data"
puts args[:sg_group_id]
end
end
desc 'build legacy data to new'
task :rebuild_database => ["playcricket:sample1", "playcricket:sample2", "playcricket:sample3"]
desc "first sample task"
task :sample1 => :environment do
puts "sample1 executed"
end
desc "second sample task"
task :sample2 => :environment do
puts "sample2 executed"
end
desc "call another rake task with arguments"
task :sample3 => :environment do
puts "sample3 executed"
Rake::Task["playcricket:sample4"].invoke("333")
end
desc "rake task with argument"
# => sample rake playcricket:sample4["767"]
task :sample4, [:sg_group_id] => :environment do |t, args|
puts "Migrating Data"
puts args[:sg_group_id]
end
end
Monday, March 18, 2013
Setting up gem aws-sdk to send emails
1) Firstly add add gem 'aws-sdk', '1.7.0' into your Gemfile
2) Create aws.rb inside initializers and then add valid amazon access key id and secret key as shown below. (aws.rb)
AWS.config(access_key_id: ENV['ACCESS_KEY_ID'], secret_access_key: ENV['SECRET_ACCESS_KEY'])
3) Add the Setup ACCESS_KEY_ID and SECRET_ACCESS_KEY into your application.yml file
default: &default
access_key_id: 'your acces key id'
secret_access_key: 'your secret access key'
development:
<<: *default
production:
access_key_id: 'your acces key id'
secret_access_key: 'your secret access key'
test:
<<: *default
4) To setup the feature in production mode add the following into your environments/production.rb
config.action_mailer.delivery_method = :amazon_ses
5) To setup in development mode add the following into your environments/development.rb
config.action_mailer.delivery_method = :amazon_ses
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
6) TO fix the following error (sample)
AWS::SimpleEmailService::Errors::MessageRejected in SessionsController#forgot_password
Email address is not verified.
7) Run the following command in console to verify
a) ses = AWS::SimpleEmailService.new(access_key_id: 'your access key', secret_access_key: 'you secret access key')
b) ses.identities.verify('email@yourdomain.com'). This is the same from email which you set while sending email. Once you run this command you will receive an email from amazon
Amazon SES Address Verificati on Request
One you approve your email then your email feature will start working.
Tuesday, February 5, 2013
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
Subscribe to:
Posts (Atom)