Migartion in Different Envirnoments
Posted on February 10, 2009, under Rails.
Wanna run db:migrate command in other environments rather than development, then it is how so:
Test Environment
rake db:migrate RAILS_ENV=test
Production Environment
rake db:migrate RAILS_ENV=production
Obviously, these commands has to be executed from the root path of the application.
See ya
Hacking a nil object / Workaround
I was looking for a way to workaround a nil object. For instance if @project.name is nil, I wanted to display as “N/A” and otherwise the project name (@project.name)
Normal Way
<% unless @project.nil? %> <%= @project.name %> <% else %> <%= "N/A" %> <% end %>
Another Way
<%= @project.name rescue nil || "N/A" %>
Just in a one single line!, Neat ah
Hope this helps!
Reset button in Rails
I was looking for a way to have a reset button in the rails way, instead of the direct HTML tag.
<%= submit_tag "Start over", :name => "reset", :type => "reset", :id => "task_reset" %>
Rmagick on Ubuntu
Posted on January 21, 2009, under Miscellaneous.
Hey, Rmagick is a big pain installing it. I was really lazy and tired to install it. Previously in windows version, you need to do lot of configurations for it and it was really time consuming one and also hectic.
But to my surprise installing it in Ubuntu (8.10) was really really a breeze and was so cool and here’s the 2 gracious command to install Rmagick in Ubuntu.
sudo apt-get install libmagick9-dev ruby1.8-dev sudo gem install rmagick
Using a partial form with form_for
I just wanted to use partial form for CRUD using Rails 2.2.2 and when i had created a form i got the following error:
undefined local variable or method `f’ for #
Old Code
<% form_for(@project) do |f| %> <%= f.error_messages %> <%= render :partial => 'form' %> <% end %>
New Code
<% form_for(@project) do |f| %>
<%= f.error_messages %>
<%= render :partial => 'form', :locals => { :f => f } %>
<% end %>
Delete .svn files from a local repository
# the following command will list all the .svn files
find ./ -name .svn
# the following command will list the SVN files and delete it
find ./ -name ?.svn? -exec rm -rf {} \;
Cleaning some untidyness
Posted on January 18, 2009, under Miscellaneous.
After a long time, I found time to clean my room and some other general works and in deed it was good to then there clean it.
Also today, I started off with my profile work in the rails, which was my long dream and also the Railscast helped me a lot in designing the app in a simple and efficient way, the right way!
So all together the day was quite with mix-up of activities including walking for a while with my mom.
So its keep me going for the next week busy schedule.
Catch you up later!
Dining @ Sachin ka Dhaba
Posted on January 17, 2009, under Miscellaneous.
After a very long time, we(Perumal, Rajha Prabhu & myself) met and as usually discussed few things (which is of no use, but a chit chatting)and it was really really good nice meeting though!
After the initial meetup, we went had a tea in a tea stall and we went back to Rajha’s house and discussed few things and time was flying like anything. Finally the clock ticked to 9′O clock and we all buzzed each other to decide where to have the dinner and on the way, Perumal catched up Sachin Ka Dabba, which is on the main road to the kodambakkam.
We went there and to our surprise, the waiters gave the newpaper. We all thought it was a news paper and inside the page, the 2nd page, it was the menu and it was quite unique i.e. the menu designed on the news paper stuff.
We order the following and it was good:
1. Tandoori Naan
2. Tomato Soup
3. Veg Makkanwala
4. Veg Kadai
5. Gobi Manchurian Dry
6. Veg Pulao
and finally 2 Gulfi Ice.
And to all, it was a nice feast and we all were full. Will visit again to this place, shortly.
Rails with mysql database
As we all knew, recent rails version 2.2.2 supports sqllite3 as a default database and when you create a new app the “database.yml” would have been configured with sqllite3.
As I am used to mysql so much, I am not prepared to migrate to sqllite and still preferred to have mysql as the default database and to do this, you need to specify another parameter -d to the rails. Here a example
rails-d mysql
This would create a new app with mysql as its database.
Hope this helps!
getopt: invalid option — ‘v’
Posted on January 15, 2009, under Rails, Shell Scripts.
Recently, I tried to install rails and it seems it all got installed successfully and in the terminal when i type
$ rails -v getopt: invalid option -- 'v' Terminating... $ sudo apt-get remove --purge rails $ sudo gem install rails Successfully installed rails-2.2.2 1 gem installed $ sudo ln -s /var/lib/gems/1.8/bin/rails /usr/bin/rails $ rails -v Rails 2.2.2