Rails ActiveRecord search records between two dates

Yeah, this is simple in Rails. date = Date.today start_date = date.at_beginning_of_month end_date = date.at_end_of_month Model.where(:created_at => start_date..end_date) This gives the records created in current month. This is simple because rails save created_at and updated_at in following format: created_at: “2018-09-03 09:49:41” But here in my case,  I had to find the records that are valid…

Read more...

PostgreSQL Basic Commands

PostgreSQL PostgreSQL, often simply Postgres, is an object-relational database management system with an emphasis on extensibility and standards compliance. This post is the collection of most commonly used PostgreSQL commands. Login to PostgreSQL psql -Upostgres Where postgres is PostgreSQL username. It will ask password of postgres user. Once you enter password it will enter to…

Read more...

MySQL tips: Back Up and Restore MySQL Database

Sometimes we have to take backup and restore our database. In this post I’m describing how to take backup from MySQL database and restore to Linux/Unix machine. If phpMyAdmin is installed to your system, you can take backup from web portal. If not installed you can take backup from command prompt. Here is MySQL command…

Read more...

Why college projects are important?

In my career I had taken more than 100’s of interviews in my company and the number is raising up. Most of candidate are freshers and some are experienced developers. Fresher candidate apply for entry level job whereas experience developers apply for mid-level and senior level position. Here I’m not talking about experience developers. There…

Read more...

Rails tutorial: Send email with rails

In rails we use ActionMailer to send email. For more detail about ActionMailer check this link: http://guides.rubyonrails.org/action_mailer_basics.html Now its time to create mailer. Use following line of command to create mailer. Here I created Blog Mailer which is used to send email to all blog subscriber when new blog published. rails g mailer ArticleMailer Which…

Read more...

Install and use MongoDB with Rails in Ubuntu

MongoDB is a scalable, high-performance, document-oriented schemaless database. In this post I describe how to install MongoDB in ubuntu 12.04 and how to use MongoDB with rails. Followings are the steps to install MongoDB 1. Add GPG Key sudo apt-key adv –keyserver keyserver.ubuntu.com –recv 7F0CEB10 2. Edit your source.list sudo gedit /etc/apt/sources.list and add this…

Read more...

Rails tutorial: Simple blog subscription feature in Rails

Here is a simple Rails MVC tutorial guide. This step by step tutorial will help you to configure routes, generate model, controller and view (i.e. MVC). It will also teach you how to send email using ActionMailer in Rails. Before start this you have to setup new rails application with MySQL database. My previous post…

Read more...

Setting MySQL database to Rails Application

MySQL is an open-source relational database management system. In this post I’m going to explain to use MySQL database to rails project. Install MySQL database if you do not have installed MySQL databse to your system.When you create new rails project with following command, it will add SQLite gem to the Gemfile, which is for…

Read more...

Use both MongoDB and MySQL database in rails project

You need to setup your rails project with both of the database connections. Firstly for MongoDB, you need to decide which driver wrapper (if you use one) are you going to use. The two common ones are MongoID & MongoMapper. Both do pretty much the same thing and make it easy to interact with Mongo…

Read more...