Posts

Showing posts from August, 2013

How Action Mailer Works in Rails

Sending emails in a rails application is very easy and quite handy using action mailer. First we will go through the basic setup of action mailer then we will go in details how it works. Step 1   We can setup a mailer class using rails generator   rails generate mailer UserMailer Step 2   Then we can create any instance method inside it.     def welcome_email(user)       @user = user       @url  = 'http://example.com/login'       mail(to: @user.email, subject: 'Welcome')     end Step 3   We can call this method form model or controller or any kind of callbacks using    Like     UserMailer.welcome_email(@user).deliver Step 4   You can set up a view template for the welcome_email in side the views/mailer directory   Like   welcome_email.html.erb   and you can specify the layout format here and can also access the instance variables defined in the       welcome_email(user) method Step 5   Additionally we can set up the smtp configuration inside

Interesting ubuntu trick

1) tail cannot watch no space left on device.    Solutions   a)  echo 900000 | sudo tee /proc/sys/fs/inotify/max_user_watches      Or Place   b) "fs.inotify.max_user_watches=16384" in /etc/sysctl.conf 2)  How to remove all files and sub-directories in a directory WITHOUT deleting the directory in bash? Solutions rm -rfv dontDeleteMe/*

How to upload Bulk file in rails 3 application

If you want to upload bulk file in rails application just follow the following steps 1) create a rails application     rails new bulk_upload 2) Add passenger in your gem file     gem 'passenger' Now try to start with your rails application with the command   passenger start by default it will run on port number 3000 Now if you try to upload bulk files lets just say more than 500 mb or 800 mb you will get an error in the time of uploading like [ error] 4840#0: *557 client intended to send too large body: 94672000 bytes, client: 127.0.0.1, server: _, request: "POST /XXX HTTP/1.1", host: "localhost:3000" so this not error of you application this is the error thrown by passenger and ngnix which is responsible to run passenger First uninstall using purge to remove even configuration files and records:   apt-get purge nginx nginx-common nginx-full Then reinstall it  apt-get install nginx If above doesn't work for you you can also

upgrade to rails 4 and ruby 2

To upgrade your rails version to rails 4 is pretty easy just follow the below steps. - I assume you have already rails installed in your system and also you are using rvm and ruby. - If you are not using rvm i recomend you to use rvm. please check the link for rvm ( http://rvm.io/ ) open a terminal and follow the steps. Step 1:  rvm get head (to get the latest version of rvm) Step 2:  rvm install 2.0.0 (to install ruby) Step 3:  rvm use 2.0.0 Step 4:  rvm gemset create rails4 Step 5:  gem install rails That's it to upgrade your rails version to rails 4 and ruby 2 in ubantu 12.04. Now if you run rails new new_app it will automatically create your rails application in rails 4 simple :) Further if you want to use both rails 3 and and rails 4 you can create a .rvmrc file in your application and mention the gem set in that file. echo "rvm ruby-1.8.7-p352@gemset" > .rvmrc And inside the file mentioned your gem set. like rvm use 2.0.0 rvm gem