Internetbureau Holder

JSONP

Jeroen Bulters wo 12 okt 11

Unfortunately, by default there is no JSONP mime type defined in Railsusage of the JSONP mime type defined in the documentation of Rails. So you’re left a bit in the void on that part. I thought Rails was a one stop solution.

Luckily, the solution is easy:

class ApplicationController < ActionController::Base
  protected
  def render_json(json, options={})
    callback, variable = params[:callback], params[:variable]
    response = if callback && variable
                   "var #{variable} = #{json};\n#{callback}(#{variable});"
                 elsif variable
                   "var #{variable} = #{json};"
                 elsif callback
                   "#{callback}(#{json});"
                 else
                   json
                 end
               end
    render({:content_t ype => :js, :text => response}.merge(options))
  end
end

And you’re able to render your jsonp replies by calling:

format.js {
    # do your thang 
    render_json result.to_json
}

Still, it’s a shame you have to hack this in yourself.

As Jan de Poorter rightfully noted: The functionality is available; just poorly documented. My lesson here is to check the Rails source more often.

Gepost in hor |  2 reacties

Easy Authentication with OmniAuth

Chiel Wester ma 08 nov 10

If you ever want to implement OAuth or OpenID to authenticate and connect users with different accounts, you should check out the OmniAuth gem! This piece of Rack middleware takes care of all the difficult stuff like having to implement and understand all the different API’s. It makes it very easy and clean to implement authentication with (for example) Twitter, OpenID and Facebook.

There are two excellent railscasts available on how to implement the oauth gem:

More information about this gem can be found at the GitHub Page

Tip: If you need nice twitter and facebook buttons on your authentication page, you can find them here

Gepost in hor |  0 reacties

RubyGems

Daniel Willemse zo 10 okt 10

Nick Quaranto recently wrote a great blog post about RubyGems, and creating gems.

It’s especially helpful for people new to ruby and rubygems, or people who want to create their own gem.

Gepost in hor |  0 reacties

ControlTower

Jeroen Bulters di 21 sep 10

Although this blog is called HollandOnRails, and this post is about something that currently does not work with Rails I thought it would still be interesting, mainly because – possibly in the future – Rails might be supported.

Yesterday, MacRuby released ControlTower 1.0.

ControlTower is a ‘simple’ web/application server built entirely on MacRuby and thus playing extremely nice with your Mac (sorry non-Macheads). It is built to run all Rack applications which are ‘supported by’ MacRuby; which means Rails is out of the picture for the moment.

What does a MacRuby webserver mean? Well, basically, you can compare ControlTower with a MacOS X version of Unicorn; but instead of using native Un*x calls (i.e. forks and selects), it uses Apple’s GrandCentralDispatch (GVD) as a socketmanager. By default you will not notice any difference with – say – Thin; as GCD uses a serial connection queue by default. But if you mac allows it, and of course you configure it correctly, it will allow you 75 concurrent incoming requests on a 8-core Mac Pro.

Scalability out of the box.

Gepost in hor |  0 reacties

Charts

Daniel Willemse ma 13 sep 10

If you want to have some charts in your application there are numerous ways to achieve this.

In the following railscast (june 19th)

Ryan Bates shows you a couple of these ways and goes indepth on a js library called Highcharts. This library is 100% js so no extra dependencies are needed, and the api is pretty straightforward aswell.

I found the examples pretty easy to follow and i’ll definitely be using them the next time i need a chart.

Gepost in hor |  0 reacties

Quicktip: hashes in find conditions

Roy van der Meij do 09 sep 10

Have you ever made a find condition with a lot of questionmarks in it where you wanted the same input for those questionmarks?

Like this:

named_scope :search, lambda {|x| {
  :conditions => ["title like ? or lead like ? or content like ?", x, x, x]
}}

You can actually use hashes in stead of questionmarks. So the above code could be refactored into this:

named_scope :search, lambda {|x| {
  :conditions => ["title like :search or lead like :search or content like :search", { :search => x}]
}}

Gepost in hor |  0 reacties

Quicktip: localghost

Wijnand Wiersma di 07 sep 10

I just wanted to share a quick tip I just found on the interwebz.

I happen to add hostnames to /etc/hosts regulary in order to have different hostnames for all apps I am working on. With localghost you can easily add, remove, enable and disable hostnames pointing to localhost with just a few mouse clicks.

For people who are not using passenger and the prefpane for development this might be very handy.

Website: http://scotchi.net/localghost/
Github: http://github.com/scotchi/Localghost

Gepost in hor |  0 reacties

to_s FTDRY

Wijnand Wiersma do 02 sep 10

Here is just a quick tip: define more to_s methods on your models to DRY up you views. It’s a very Ruby thing to do and if you keep this method fairly on top of your classes it won’t be very confusing for other developers.

For one project I have 3 models: include, exclude and split. When I want to display them I only want to show the only defined property they have: path

I display them regularly in views and it gets used in background processes where it is concatenated into a bigger string.

So instead of writing include.path everytime I went for this approach:

def to_s
  path
end

From now on I can do something like this in my views:

<li><%= include %></li>

And where it gets concatenated:

"#{first_include} something here #{second_include}"

or a array gets joined:
includes.join(" ")

Another nice example might be a person class where you display the persons name regularly in views. If you keep the parts of the name in multiple properties you are getting a bigger win:

def name
  [first_name, last_name_prefix, last_name].reject{|x|x.blank?}.join ' '
 end

So if you display an object as a string a lot defining a to_s method and just put in your plain object in your view will certainly a nice way to get more DRY.

Gepost in hor |  0 reacties

It's Rails 3 time!

Chiel Wester ma 30 aug 10

After years of development by the Rails Community the 3rd version of Rails is finally ready! The number of new features and improvements is enormous!

Are you ready to upgrade your application to this new version of Rails? Just use the Rails 3 upgrade handbook

Gepost in hor |  0 reacties

Rails 3.0: Release candidate 2

Stephan Kaag vr 27 aug 10

According to DHH the release candidate process is progressing as planned. This second candidate has very few changes over the first, which means that unless any blockers are discovered with this release, we’re targeting the final release of Rails 3.0 for this week(!!!).

Gepost in hor |  0 reacties

Welcome to Holland On Rails

This weblog is the official Ruby techblog from the guys at Holder, a Ruby development company. Holder is also the company behind the RubyAndRails Europe Conference in Amsterdam.

Recente Jobs


Bekijk alle jobs »»

Gereedschapskist

Onmisbare tools voor
iedere 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 ;-) Recommend Me

Stephan Kaag

Het eerste Rails coreteam- member uit Nederland? Rails evangelist van het eerste uur.

Paul Engel

Én Rails programmeren én interfaces designen? Je zou hem superman kunnen noemen..

Dax Huiberts

Official Zip-Programmer, skinny code is helemaal zijn ding. Haalt meer code weg dan dat er bij komt.

Freek Monteban

Het nieuwste telg uit het Holland on Rails nest! Hij doet niets anders meer!

Johan Vermeulen

De stylesheet-koning uit de kop van Noord-Holland!