Archive for February, 2009
Run Controller Spec
Posted on February 21, 2009, under Rails, Shell Scripts.
If you just wanted to run only the controller specs, then you have to use the following command
rake spec:controllers
Restore the deleted files with GIT
Today, it was a shock, that I have deleted few files without my knowledge. Fortunately, before deleting I had committed the files and so no much of tension. You can use the following commands to restore it.
View the list of deleted files:
git ls-files -d
This will list the deleted file and lets restore it now.
git ls-files -d | xargs git checkout --
Hope this helps somebody.
Cheers!
Select Random Records
I wanted for some reason to have random records from a model without any condition, just random records and here’s how you have to do it.
Hope this helps somebody!
Cheers!!!
Multiple Unfuddle Accounts
I was having my own free unfuddle account and my work also had another unfuddle account. Now I had configured my public key for my work account and when I updated the same public key for my personal account, it didn’t accept it.
It throwed a error already this key is in use.
So, what the hell do I have to do? Here’s what I did to solve it….Simple steps though
STEP 1: Create another public key
ssh-keygen -t rsa -f personal_unfuddle
As you know it will generate a key and store it file name “personal_unfuddle” -f parameter is a optional parameter and it will store it in that file.
Now you have to view the generated file to update the public key in the unfuddle
cat personal_unfuddle.pub
Copy paste the key into your unfuddle account.
STEP 2: Identifying the Key pair for the multiple account.
Create/Edit a file named “config” in youe .ssh folder
sudo vim config
Paste the following code into the config file
Host work.unfuddle.com User git IdentityFile ~/.ssh/id_rsa Host personal.unfuddle.com User git IdentityFile ~/.ssh/personal_unfuddle
After few mins, this should start working.
Hope this helps someone
Photo Gallery up in seconds
Posted on February 16, 2009, under Miscellaneous.
Hey, recently I was looking for a way to display the picasa web albums on my blog and discovered a really cool plugin, with so sweat.
http://wordpress.org/extend/plugins/kpicasa-gallery/installation/
This was really a very cool plugin and its so easy to get it done in fraction of seconds…..Way too fast.
Also you can use specify the Albums that you wanted to display. For instances, you may wanted to show certain albums and not all.
Really cool ah!
Rails Default Layout
As we all know, for any controller, by default rails looks the controller name .rthml files and if it doesn’t exists then it looks application.rhtml.
Since my site is very simple, I don’t have many layouts and just one layout and so i stored the layout file in app/views/layouts/application.html.erb and i removed all other layout files so that by default it will read application.html.erb.
Hope this helps somebody!
Pads
Load Fixtures into the Database
I was looking to load the fixtures into my database and it is very simple. Please look at the following code
rake spec:db:fixtures:load
Hope this helps somebody.
Cheers!
Pads
Migartion in Different Envirnoments
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" %>