You are hereRails
Rails
My day job involves mostly coding in Ruby for the Ruby on Rails web application framework.
The case of the missing javascript function
I just got finished debugging an odd javascript problem where the browser could not find a function that I had defined in an included .js file. It was odd because there were other functions in the same file that were found, but not this particular one. Here's the code I was using:
<input type="button" id="done_ts_confirm" onclick="done_ts_confirm(); return false;" value="Continue">
I was running Firefox, and the error console reported "Error: done_ts_confirm is not a function"
Can you spot the problem? It turned out to be a naming conflict between the function name and the "id" attribute on the button... they were both the same. Once I renamed the id attribute, everything was OK.
Fun with anagrams
Anagrams are fun. The Internet Anagram Server proves it. Although the server is overloaded at times, when it is working it's almost spooky the word combinations it comes up with. Take for instance these variations on "Michael G Hiemstra":
him mega rails tech
hitch me a rails gem
rails might ache me
him teach rails gem
rails mace he might
them rails magic eh
me rails mach eight
OK, so I cheated a little and required the word "rails" using the Advanced Anagramming option. You can't blame me for trying!
Jason Fried on teaching to get more business
The 37signals blog pointed me to a video talk by Jason Fried (founder and CEO of 37signals) where he talks about how businesses can use teaching as a way attract and retain customers. To paraphrase the 14 minute talk, telling your customers how and why you do what you do can actually make you money. He talks about how 37signals repurposed a collection of their "lessons" (describing the strengths of their own application development "philosophy") from their blog into a book and a conference... both of which made them money.
Problems with protected controller methods
I struggled with this for awhile, maybe this post will save someone else the trouble?
By default, methods in your Rails controller can be accessed from the URL of your application. If you have a controller method named "car" and a method named "start", then using the URL car/start will execute the "start" method.
But, there are some cases where you might want a method in the controller, but not have it accessible. In this case, you can make the method "protected", and only methods within the same controller will have access to it.
I was happy and successful understanding these details until I tried to use a protected method inside an AJAX-style page update block. In this case, the protected method couldn't be found. I couldn't understand why the method worked in most cases, but not this one. I would get an error like:
NameError (undefined local variable or method `top_level_nodes' for #<#:0x46e7ec8>):
Then I realized that putting the call to my protected method inside a block like this:
render :update do |page|
protected_method
end
... is actually calling the method from a different class, and that's why the method is not found.
Once I realized this, I was able to move the call outside of the render block and I was good. I'm not sure if there is any other way to handle cases like this. I also noticed that the call would fail similarly inside a "for x in y" block.