Open source flash charts like google analytics
We all want our charts to look like the ones in google analytics. Well know there is a way the “Open Flash Chart” project. The guys over at pull monkey have released a plugin for rails that helps you get in these great charts. Ill be testing this plugin very soon and ill put up my experience and a little walk through. In the mean time if you want to check out the project have a look here
Here is an example of what the charts look like

Using Javascript Code for RJS Instead of IDs
UPDATE: JavascriptGenerator has a method name literal that will do the exact same thing, so the code below should do the trick:
page.insert_html :bottom, page.literal("$$('p.welcome b').first()"), "Some item"
Bill Burhcam over at Meme Rocket made a post that *almost* solved a problem for me the other day. We’re currently doing some work that ends up creating html. Pretty standard stuff, but for a few reasons that aren’t really worth going into we can’t easily rely on our element ids being unique. The prototype functions ‘up’ and ‘down’ are perfect for this situation though.
So our problem basically boils down to this – RJS converts this code:
page.insert_html :bottom, "$$('p.welcome b').first()", "Some item"
into this javascript:
new Insertion.Bottom("$$('p.welcome b').first()", "Some item"
Because the $$(‘p…’) is in quotes, Insertion.Bottom just looks for an element with that id. Which isn’t what we really wanted.
After digging around in the ActionView source for a while I found JavascriptGenerator::GeneratorMethods and its javascript_object_for method. It turns out that if you pass in a ActiveSupport::JSON::Variable then insert_html will behave how we want. So for the example above, the code below will work as expected.
js_literal = "$$('p.welcome b').first()" js_literal = ActiveSupport::JSON::Variable.new(js_literal) page.insert_html :bottom, js_literal, "Some item"
will output:
new Insertion.Bottom($$('p.welcome b').first(), "Some item"
Thank you open source.
Ruby on Rails 2.3 Searchable API Doc
A developer by the name of Vladimir Kolesnikov has put together a nice little searchable API doc for rails. Its been updated for rails 2.3.2 (Latest Version) and you can either download it or browse online. Currently its been tested with Safari 4, Firefox 3, Opera 9.5 Internet Explorer is currently unsupported but who uses IE anyways.
You can download it here
Ajax.Updater and javascript
Ran into a little problem today which made me think for a second. I have a Javascript function that runs once a calendar control is closed. It just passes a parameter to a action which renders a view nothing fancy.
So my onClose function looks like so
function onClose(cal) {
var p = cal.params;
new Ajax.Updater('overlapping', '/visits/new', {
parameters: { start_date: p.inputField.value; },
evalScripts: true
});
cal.hide();
};
This will fire once the calendar is closed. ‘Overlapping’ is the ID of the Div ill be updating and ‘/visits/new’ is the path of the action in your controller. This will then pass the start date param to the action which can then be used in the view. The problem l had is that l had some javascript on the partial that was not executing. Had to think for a minute and then it turned out that evalScripts is false by default thus the javascript was not executing.
So its as simple as having the following as a param in your Ajax.updater
evalScripts: true
Once you have done that your good to go.
Rails 2.3 is out
Finally Rails 2.3 is out. Officially its tagged as 2.3.2 from memory. So what are you waiting for update already. Just run the following command in your terminal and your on your way. Sorry windows users find your own way
sudo gem install rails
Check out the release notes here
Please accept the terms of service and privacy policy
If you need users the accept the terms of services and privcay policy or your rails application there is a simple way to handle this without a database field or javascript. It’s using the validation methods built into rails. Simply add the following code to your User model for example
validates_acceptance_of :terms_of_service
Then in your view add the following to your view and you will get a checkbox on the page that users will be required to check.
<%= check_box :user, :terms_of_service %>
This will then add this validation rule to your models validation rules and when you try to submit the form without checking the checkbox you get a nice little validation message letting you know hey you need to accept this.
Of course you can have your own validation message displayed like so
validates_acceptance_of :terms_of_service, :message => ' and the privacy policy must be accepted'




