Rails 3 screen casts
Johan Vermeulen wo 09 jun 10
Gregg Pollack just released a couple of screencasts about all what’s new in Rails 3.
These are the topics that will be covered:
Getting Started & Action Dispatch
Active Relation & Active Model
Cross-site scripting & Unobtrusive JS
Have fun watching!
Gepost in hor | 1 reactie
$ 3.0.0.beta4
Stephan Kaag di 08 jun 10
The Rails core team is very pleased to announce Rails 3 beta 4, which they will be hammering on and tuning during RailsConf. At the end of RailsConf, they will be putting out the release candidate.
You can install the latest beta with gem install rails --pre
Gepost in hor | 0 reacties
Unroller
Jeroen Bulters ma 07 jun 10
When working with a new piece of code, being a new plugin, gem or just some code someone else wrote, and you want to familiarise yourself with the inner workings you can do a few things.
Play around with it in irb (or script/console) and try out different options, while keeping the code as a reference. Or you pull out the debugging-swiss-army-knife named Unroller (available as a gem with the same name).
Unroller is a custom tracing module designed with this kind of situations in mind and is very easy to use.
Image the following – useless – piece of Ruby code which calls the same function 4 times, followed by some other function.
require 'rubygems' require 'unroller' class Recurse def self.some_recursive_function(times, callback, depth=0) if depth == times self.send(callback) return else puts "Depth is #{depth}" some_recursive_function(times, callback, depth+1) end end def self.end_of_recursion_callback puts "End of recursion" end end Recurse.some_recursive_function(3, :end_of_recursion_callback)
Of course, this example is quite trivial, but imagine for a second we do not understand how it works.
By wrapping the method call in a Unroller block we can easily generate an easily understandable stacktrace.
So, we replace the Recurse#some_recursive_function call with the following:
Unroller::trace do Recurse.some_recursive_function(3, :end_of_recursion_callback) end
And run the file again.
This time, we are presented with a nice stack trace showing each step of the execution:
| Recurse.some_recursive_function(3, :end_of_recursion_callback) | unroll.rb:23 | \ calling Recurse::some_recursive_function Recurse::some_recursive_function (unroll.rb:6) (line): | | (times = 3; callback = :end_of_recursion_callback; depth = 0)... def self.some_recursive_function(times, callback, depth=0) -> if depth == times self.send(callback) return else puts "Depth is #{depth}" some_recursive_function(times, callback, depth+1) end end --- SNIP FOR BREVITY --- Recurse.some_recursive_function(3, :end_of_recursion_callback) Unroller::trace do Recurse.some_recursive_function(3, :end_of_recursion_callback) end | | | | / returning from Recurse::some_recursive_function | | | / returning from Recurse::some_recursive_function | | / returning from Recurse::some_recursive_function | / returning from Recurse::some_recursive_function
Unroller shows us all the code being executed, the current line and the depth of the function in the stacktrace.
This kind of output can come quite in handy when debugging complicated situations like ActiveRecord filter chains.
More information on Unroller is found at http://unroller.rubyforge.org/.
Gepost in hor | 0 reacties
$ 3.0.0.beta2
Stephan Kaag di 06 apr 10
It took longer than they thought, but then again, what doesn’t? The second beta release of Rails 3.0 is released and hopefully the last stop before a release candidate.
You can install beta 2 and try it out with new and existing applications. (gem install rails —prerelease after you make sure you’re on Ruby Gems 1.3.6 with gem update —system).
Gepost in hor | 0 reacties
Itsy bitsy monad
Jeroen Bulters wo 31 mrt 10
Functional programming has been sort of a hype lately. Therefore I thought it would be nice to try and apply some concepts from functional programming languages to Ruby (and, ergo: Rails).
One of my personal best friends in Ruby is Mr. NilClass (not really), he always makes me add stuff to my if statements to check if he’s there. So, I’m constantly doing stuff like:
if (customer && customer.address && customer.address.zipcode)
Sure, not to big of a deal, but I just don’t like it.
Several functional programming languages know a concept known as Monad’s. I’m not going to give an introduction to Monad’s (read a good one at moonbase), but I can give a useable monad implementation in Ruby to illustrate the concept.
Monad’s basically wrap an object in a container, allow you to perform actions on it and – when you’re done playing – unwrap the resultant value from the monad.
So, after constructing the monad, and connecting some of the functionality to the Ruby Object class. I should be able to do:
any_object.if_possible?.other.value #=> 'the value I put in here' nil.if_possible?.other.value #=> nil any_object.if_possible?.nil.value #=> nil
All without yielding any exceptions.
Let’s start with adding the if_possible? method to wrap our object in a monad.
class Object def if_possible? Monad::Maybe.new(self) end end
Note: This monad is actually called the Maybe monad in a.o. Haskell
Now, we create the monad itself (nicely in the Monad module). Please note that the mentioned unwrapping is achieved through the attr_accessor and that you should choose a more semantic name for it.
module Monad class Maybe # Unwrapping through the accessor attr_accessor :value def initialize val @value = val end def monadBind proc if @value != nil # We get the result, and rewrap # that in a the Maybe monad again. proc.call.if_possible? else self end end def method_missing(method_name, *args) monadBind(Proc.new {@value.send(method_name, *args)}) end end end
Now let’s try this out with the following file:
class Test1 attr_accessor :other def initialize(other) @other = other end end class Test2 attr_accessor :value def initialize(value) @value = value end end
Load it into irb (or put the following in the same file) and try this:
value = Test2.new(true) working = Test1.new(value) puts working.other.value puts working.if_possible?.other.value.value puts nil.if_possible?.other.value
When run, it produces the following output, without throwing exceptions:
[bulters@~/monadic_art]$ ruby monad.rb true true nil
So, what did we do? Basically, we constructed a nicer way to check for nil’s, and propagating the handling of it back to our program.
The line
if (customer && customer.address && customer.address.zipcode)
can now be written as:
if(customer.if_possible?.address.zipcode.value)
which is – in my opinion – not only shorter, but also a bit easier on the eyes.
Gepost in hor | 1 reactie
ScotRubyConf 5K
Stephan Kaag wo 24 mrt 10
As you might know already a small part of the HoR crew will attend this year’s ScottishRubyConference which happens to start next friday.
We will all participate in a local Run for Charity.
The run will take place in the early evening of 26 March, when many of the Scottish Ruby Conference Delegates and speakers will decamp to Portobello to take part in the 5k race.
The ScotRubyConf5k is inspired by last year’s RubyConf5k, which raised over $1,300 for the Leukemia & Lymphoma Society.
38 runners have now registered for the SRC 5k race. That’s quite a pack! Whatever your pace, you won’t feel alone. The route1 follows the Portobello promenade, which is as flat as can be. If you’ve never raced before, it will be a gentle introduction, or if you’re trying to set a new personal best then this could be the place to do it.
Gepost in hor | 0 reacties
Debugging under Passenger
Jeroen Bulters do 18 mrt 10
Sometimes… you just have to debug something in a ‘live’ (i.e. staging) environment. Or you just enjoy using Passenger as a development platform. Either way, when using Passenger, you lose the plain-old “—debugger” option which – in my opinion – has proven itself to be indispensible to debug Rails applications. Luckily, there is a solution: ruby-debug.
To use ruby-debug with passenger, we specify the following in our environment file (be it production or development):.
if File.exists?(File.join(Rails.root,'tmp', 'debugger.txt')) require 'ruby-debug' Debugger.wait_connection = true Debugger.start_remote File.delete(File.join(Rails.root,'tmp', 'debugger.txt')) end
Starting a debugger waiting for a remote connection if the debugger.txt file exists in our tmp directory. Just touch both the tmp/debugger.txt file and the tmp/restart.txt file and a debugger session will be waiting for you as soon as the Passenger process has respawned.
Connect with the debugger with “rdebug -c”; et voila!
One drawback, the incredibly handy irb function of rdb is not available in remote-mode.
Gepost in hor | 0 reacties
Adding Hoptoad support to Delayed::Job
Stephan Kaag di 16 mrt 10
Altough Hoptoad might be installed in your Rails application, the errors that are raised within delayed-jobs will not be reported to this excellent service.
Why is that? Delayed-job has it’s own exception rescuing mechanism and the Hoptoad hook isn’t called by default. If you want to report all delayed-job’s exceptions to Hoptoad you can use a hook-script like this.
begin Delayed::Job.logger.info "Adding Hoptoad support to Delayed::Job" begin module Delayed class Job def invoke_job_with_hoptoad if defined?(HoptoadNotifier) Delayed::Job.send(:define_method, :invoke_job_with_hoptoad) do begin invoke_job_without_hoptoad rescue Exception => e HoptoadNotifier.notify(e, :cgi_data => self.attributes) raise e end end else Delayed::Job.send(:define_method, :invoke_job_with_hoptoad) do invoke_job_without_hoptoad end end invoke_job_with_hoptoad end alias_method_chain :invoke_job, :hoptoad end # Job end # Delayed rescue Exception => e Delayed::Job.logger.error(e) raise e end end
Gepost in hor | 0 reacties
VirtualBox and Ruby
Gawin Dapper do 11 mrt 10
Over the last few years I worked with a lot of different virtualisation products. Ranging for VMware ESX and XEN clusters to simpeler solutions like VMware Workstation and Fusion, Parallels, but also with VirtualBox. Innotek introduced VirtualBox 3 years ago, and since that has been bought by Sun Microsystems, which was recently bought by Oracle.
I have been using VirtualBox since the Beta, and I’m still a big fan. Over the periode of 3 years it has grown into a very rich feature set, and works on most operating systems. Features I really like are Snapshots, the Public API, Raw hard disk access and the abillity to use VMware VMDK and Microsofts VHD disk images. Since 3.1 it also supports Teleportation, which lets you migrate your VM live (with no downtime) from one physical machine to an ohter.
Now you might wonder why I would write this on a Ruby blog?
Well, there is a very nice VirtualBox gem which allows you to manage your VM’s using Ruby. It is modeled after ActiveRecord, so most of you should feel right at home.
To get started, just follow the Getting Started Guide
Gepost in | 0 reacties
Webservices in RubyOnRails
Chiel Wester wo 10 mrt 10
Since the launch of rails 2.0, the standard support for generating soap services with rails was removed. SOAP was replaced for standard REST support. This was done because Rails became entirely resource driven and uses REST as the architecture to accomplish that. SOAP on the other hand implements specific method names and sends all calls all these methods using a POST request.
So what if your client application requires a soap service and you therefore have the need to develop a soap service in your rails application? You will need actionwebservice for that. Luckily actionwebservice was not lost entirely when rails dropped support for SOAP. Simply install the pantzel-actionwebservice gem and you are ready to generate a basic SOAP service.
The good thing of actionwebservice is that you don’t have to worry about creating a WSDL. Simply define the structure of your webservice, start the application and go to http://localhost:3000/webservicename/wsdl and the wsdl is presented to you generated from the webservice api definition!
For examples of how to use the actionwebservice gem, there are some good examples in the example directory of the gem itself.
Gepost in hor | 0 reacties
Welkom op Holland On Rails
Het startpunt voor Ruby On Rails in Nederland. Vind de laatste technieken, meningen en nieuwtjes.Recente Jobs
Gezocht: Ruby On Rails ontwikkelaar (junior of senior)
Eet, drink en droom jij over Ruby On Rails? Wil jij het liefste dag en nacht bezig zijn met jehobby; super coole webapplicaties ontwikkelen in Ruby On Rails?
Dan willen wij jou graag een podium bieden om je Ruby skills te vertonen aan onze nationale en internationale klanten!
@ Internetbureau Holder, Obdam
Bekijk alle jobs »»
Gereedschapskist
Onmisbare tools vooriedere developer!
- Ruby On Rails
Framework voor de web 2.0 developer. Eindelijk vooruitgang! - TextMate
Editor for true pro's
Typ, tab, top :-)
Nee, niet voor Win. - Made On A Mac
En nou is het over met die saaie grijze Windows bak van je!
Auteurs op deze site
Chris Obdam
'Less is more' evangelist, past dit ook dagelijks toe op zijn tandenborstel.Chiel Wester
Snelheidswonder op Ruby wielen. Leuk om mee te pair-programmen ;-)