Wednesday, July 28, 2010

Solution: webrat's save_and_open_page and open_error_files are not opening the browser automatically

If you are using webrat's features like save_and_open_page or config.open_error_files and is not automatically opening your browser then you might need to install launchy, It fails silently, I know, it should be more informative:
sudo gem install launchy
More info about launchy: http://rubygems.org/gems/launchy/

Tuesday, July 20, 2010

Passing parameters to before_filter methods in Rails

If you have methods in your controller class that requires parameters you can still user them as filters.
Example:
def require_role(role)
#do some stuff with 'role' parameter
end
We can use it like this:
before_filter do |controller_instance|
controller_instance.require_role :admin
end
In fact, you can still use :only and :except if you need it, example:
before_filter :only => :index do |controller_instance|
controller_instance.require_role :admin
end
Have a nice day.