Showing posts with label ruby on rails. Show all posts
Showing posts with label ruby on rails. Show all posts

How to precompile assets in production server of rails?


If you are hosting your sites with apache and passenger on ubuntu and things are not working as expected in production environment then you should try these three steps, which often works for me :

1. Precompile your assets : It would take time so be patient and let rails do it works.

cg@ubuntu:~/your_app$RAILS_ENV=production rake assets:precompile

2. Run Migration on production Server : Sometime we forget to migrate our data in production server. We know that rails have three different databases for development, production and testing, therefore running migration on production server is important.

cg@ubuntu:~/your_app$rake db:migrate RAILS_ENV="production"

3.Restart Apache : With passenger and apache, if you do slightest of change you need to restart apache again. There are other solutions to automate this but for now just do it.

cg@ubuntu:~/your_app$sudo service  apache2 reload

Heroku Users:

Asset Pre compilation in heroku is somewhat different than local computer because we need to do it in production environment.

cg@ubuntu:~/your_app$RAILS_ENV=production bundle exec rake assets:precompile

After running above command use git and the upload that git to heroku.

cg@ubuntu:~/your_app$git add .
cg@ubuntu:~/your_app$git commit -m "assets precompile on heroku"
cg@ubuntu:~/your_app$git push heroku master

I hope that helped!

How to install ruby on rails on windows?

Installing ruby and rails is not as easy on windows as it is on Mac or at Ubuntu, but things are changing now. You can install and create rails applications on a fly with existing tools for windows.In this post we will see how to install ROR in a step by step procedure :

How to setup mysql database.yml in Ubuntu ?

Steps which I am sharing with you has worked for me and I hope that would help you in connecting your mysql database to your ruby on rails application.

Step 1. Open terminal and execute this command : sudo apt-get install mysql-server libmysqlclient-dev libmysql-ruby

Step2. Change Directory to your application folder ,like cd /rails_projects/cg

Step3. Now ,install mysql gem : sudo gem install mysql

Step4. Configure your database.yml :  sudo gedit configure/database.yml

Step5.Paste this code:
development:
  adapter: mysql
  encoding: utf8
  database: yourdatabase_development
  pool: 5
  username: root
  password: yourpassword


test:
  adapter: mysql
  encoding: utf8
  database: yourdatabase_test
  pool: 5
  username: root
  password: yourpassword



production:
  adapter: mysql
  encoding: utf8
  database: yourdatabase_production
  pool: 5
  username: root
  password: yourpasswod


Done! Now create database using rake:db create  and enjoy!

No Route Matches hello html rails tutorial

I was following rails tutorial book and found "no route matches" error.
I found funny and simple solution of this problem , just restart your computer and start rails server using "rails s" command in sample_app directory. Its done.


Why rails giving this error?

Because it is taking application root of demo_app instead of sample_app, for that reason we need to restart our rail server. I didn't found simple solution for doing that so restarting computer itself does the trick for me.