Use the following commands:
I can only find copy and drop commands for doing this. Please comment here if you find a single command to do this.
> db.copyDatabase('old_db_name', 'new_db_name');
> use old_db_name;
> db.dropDatabase();
Use the following commands:
I can only find copy and drop commands for doing this. Please comment here if you find a single command to do this.
> db.copyDatabase('old_db_name', 'new_db_name');
> use old_db_name;
> db.dropDatabase();
Create a ruby class called Test
class Test
def cv=(value)
@@cv = value
end
def cb=(value)
@cb = value
end
def cv
@@cv
end
def cb
@cb
end
end
=> nil
Then create an instance of this class a and b
Try accessing the class variable without initializing it.
a = Test.new
=> #
a.cv
NameError: uninitialized class variable @@cv in Test
from (irb):9:in `cv'
from (irb):16
Initialize the class variable with some data. And add values to the instance variable of a and b.
a.cv=45 => 45 a.cv => 45
b = Test.new => # b.cv => 45 a.cb = 34 => 34 a.cb => 34 b.cb => nil b.cb = 90 => 90 b.cb => 90
If we have some keys and values and we just need to create a url with this data just pass the url and hash as a parameter to the following method.
def generate_url_with_params(url, params = {})
uri = URI(url)
uri.query = params.to_query
uri.to_s
end
If you want to get rid of the parameters from a url use the following method.
def generate_url_without_params(url, params = {})
uri = URI(url)
full_params = Rack::Utils.parse_query uri.query
params.each do |key, val|
full_params.delete key
end
uri.query = full_params.to_param
uri.to_s
end
Here it is, a simple captcha for Rails applications.
To set up, add the following line to your Gemfile
gem "galetahub-simple_captcha", :require => "simple_captcha"
Run rails generator
rails generate simple_captcha
Do db Migration
rake db:migrate -t
In your view file add
%= show_simple_captcha %
Add the following in yml file
en.yml:
en:
simple_captcha:
label: "Enter the above code"
placeholder: "Enter here"
In controller just include captcha helpers module
class ApplicationController < ActionController::Base include SimpleCaptcha::ControllerHelpers end
Use this code in the controller for the captcha validation
if simple_captcha_valid? do this else do that end
If you are getting errors like:
installing pdf-reader 1.3.3
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/vagrant/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20150306-5919-1rr483p.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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.
when trying to install pg gem,
you are just missing some dependancy library related to libpq. Install the following package
$ sudo apt-get install libpq-dev
then do
$ gem install pg -v 'version-no'
then do
bundle install
Before reinstalling mongodb, in your linux system check whats installed in the system
$ sudo dpkg -l | grep mongo ii mongodb-org 2.6.3 amd64 MongoDB open source document-oriented database system (metapackage) ii mongodb-org-mongos 2.6.3 amd64 MongoDB sharded cluster query router ii mongodb-org-server 2.6.3 amd64 MongoDB database server ii mongodb-org-shell 2.6.3 amd64 MongoDB shell client ii mongodb-org-tools 2.6.3 amd64 MongoDB tools
Remove all$ sudo apt-get remove mongodb*
Install mongodb again, check mongodb org
$ sudo apt-get install -y mongodb-org
For particular version
$ sudo apt-get install -y mongodb-org=2.6.5 mongodb-org-server=2.6.5 mongodb-org-shell=2.6.5 mongodb-org-mongos=2.6.5 mongodb-org-tools=2.6.5
check whats newly installed
$ sudo dpkg -l | grep mongo ii mongodb-org 2.6.8 amd64 MongoDB open source document-oriented database system (metapackage) ii mongodb-org-mongos 2.6.8 amd64 MongoDB sharded cluster query router ii mongodb-org-server 2.6.8 amd64 MongoDB database server ii mongodb-org-shell 2.6.8 amd64 MongoDB shell client ii mongodb-org-tools 2.6.8 amd64 MongoDB tools
check mongodb server status
$ sudo service mongod status
Start mongodb server
$ sudo service mongod start
Start mongo shell
$ mongo
check mongodb log file here
$ tail -n 200 /var/log/mongodb/mongod.log
When I was working with rails and paperclip I got this error.
Paperclip::AdapterRegistry::NoHandlerError
= form_tag my_path, :method => :post do ------- = file_field_tag "attachment" -----
I submitted a form and it was not saving. There I found that the form sending a file too. I missed
:multipart => true
option in the ‘form_tag’ when submitting the form. The form really not sening a file and paperclip not getting an attachment. So it throws this error.
= form_tag my_path, :method => :post, :multipart => true do ------- = file_field_tag "attachment" -----
Using render partial with collection how to find the index of the records?
Somewhere I found that someone is commented like,
“It seems this is an undocumented feature of rails.”
Anyway we can find this by using ‘recordName_counter’.
Render a partial with collection
= render :partial = > "person", :collection => @winners
Name: = person.name
In Partial write
Rank: = person_counter + 1
Name: = person.name
Result
Rank: 1 Name: Peter
Rank: 2 Name: Paul
Rank: 3 Name: Mary
Go to the mysql console and follow these steps
> use mysql;
> update user set password=PASSWORD("mynewpassword") where User='root';
> flush privileges;
> quit
I got this error while working with paperclip. The project was stable and I have no idea why this error happens at this point of time.
[paperclip] An error was received while processing: # [paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for paperclip-reprocess20110822-2281-19969sz
So I was lazy to fix the error, and find that I have no imagemagick installed in my new system. After installing ‘imagemagick’ it got fixed.
$ sudo apt-get update $ sudo apt-get install imagemagick --fix-missing