I was getting this error in to_param method. I had to explicity call to_s on id to fix it. My to_param method :
def to_param
name_slug ? "#{id.to_s}-#{name_slug.parameterize}" : id.to_s
end
If the name slug is not nil then it uses that to generate the SEO friendly URL otherwise it uses the id.
Thursday, October 15, 2009
Saturday, September 19, 2009
-bash: mate:command not found
In Mac OS X 10.5.8 add the line: alias mate='open -a TextMate.app'
to your ~/.bashrc file
to your ~/.bashrc file
Thursday, September 10, 2009
Hivelogic instructions for ruby path
If which ruby shows /usr/bin/ruby instead of /usr/local/bin/ruby , it means you have not set the PATH correctly. I had to add a line: source ~/.profile to the ~/.bash_profile file. Now whenever you bring up the terminal and when you check the PATH, usr/local/bin will come before /usr/bin and the latest installed version will be picked up (which ruby will output /usr/local/bin/ruby)
Monday, August 24, 2009
Monday, August 17, 2009
Scriptaculous Rails - Complex Forms Railscasts IE fix
$($(this).parentNode).remove() works on both FF and IE.
Thursday, August 13, 2009
How to prevent the active_record output in rails console
end the statements with ; nil
Eg: list = Blog.find(:all)
list.each do |x|
puts x.title
end ; nil
Eg: list = Blog.find(:all)
list.each do |x|
puts x.title
end ; nil
Tuesday, July 21, 2009
Monday, July 20, 2009
How to dynamically insert html code with Javascript and Rails
somePage.html.erb
<%= text_field("myObjectName", "someAttribute", "onchange" => "calculateMyVar()") %>
When the user moves out of the text field, the javascript will be called.
<% if @myVar.nil? %>
<% else %>
<%= @myVar %>
<% end %>
Notice that, in order for this to work the value between the td tags is empty. If you have some dynamic output tag as shown in the else section then the javascript will not work. The above code will work for new and edit cases.
Include the following javascript within the head section of the html.erb file.
function calculateMyVar()
{
var f1 = document.getElementById('field1').value;
var f2 = document.getElementById('field2').value;
document.getElementById('myVar').innerHTML = f1 - f2
}
<%= text_field("myObjectName", "someAttribute", "onchange" => "calculateMyVar()") %>
When the user moves out of the text field, the javascript will be called.
<% if @myVar.nil? %>
<% else %>
<% end %>
Notice that, in order for this to work the value between the td tags is empty. If you have some dynamic output tag as shown in the else section then the javascript will not work. The above code will work for new and edit cases.
Include the following javascript within the head section of the html.erb file.
function calculateMyVar()
{
var f1 = document.getElementById('field1').value;
var f2 = document.getElementById('field2').value;
document.getElementById('myVar').innerHTML = f1 - f2
}
Rails Documentation Bug for Time extension
If you have a table with an attribute of type :time then to access the minutes, use min method. There is no minute or minutes method on Time extension object in ActiveSupport.
You can list all the methods available by: myActiveRecordObject.game_time.methods.sort
You can list all the methods available by: myActiveRecordObject.game_time.methods.sort
Friday, July 17, 2009
How to format date in US format in Rails
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:default]='%m/%d/%Y'
Thursday, July 16, 2009
How to replace space with comma in sed
test.txt :
Bugs Bunny
Daffy Duck
cat test.txt | sed -e 's/[ ]/,/g'
outputs:
Bugs, Bunny
Daffy, Duck
cat test.txt | sed -e 's/[ ]/,/g' | sed 's/$/,/'
will append comma to the end as well, so:
Bugs, Bunny,
Daffy, Duck,
Bugs Bunny
Daffy Duck
cat test.txt | sed -e 's/[ ]/,/g'
outputs:
Bugs, Bunny
Daffy, Duck
cat test.txt | sed -e 's/[ ]/,/g' | sed 's/$/,/'
will append comma to the end as well, so:
Bugs, Bunny,
Daffy, Duck,
Tuesday, April 28, 2009
Wednesday, March 04, 2009
How to load a specific version of gem
For some reason if you want to use specific version of gem installed on your system:
require 'rubygems'
gem 'activesupport', '=1.4.2'
require 'active_support'
require 'rubygems'
gem 'activesupport', '=1.4.2'
require 'active_support'
Friday, February 27, 2009
How to check if CRON service is running
You can make sure the cron service is running by running 'sudo /sbin/service crond restart'.
Thursday, February 05, 2009
Thursday, January 01, 2009
Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configuration
This error is caused if mod_ssl is not installed. On Cent OS : sudo yum install mod_ssl to get SSL working.
Subscribe to:
Posts (Atom)