<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><description></description><title>Rails of Tolosa</title><generator>Tumblr (3.0; @jlstar)</generator><link>http://joelazemar.fr/</link><item><title>Override Devise Registration Controller</title><description>&lt;h2&gt;Override Devise&lt;/h2&gt;

&lt;h3&gt;Introduction&lt;/h3&gt;

&lt;p&gt;I want to create a user directly linked to a company. In this case you must change the basic behavior of Devise . Of course you can override by copying the controller in app/controllers and indicating Devise to use your new route, but I wanted to find an nicely solution, I got a ticket that has put me on the good way.&lt;/p&gt;

&lt;h3&gt;Models&lt;/h3&gt;

&lt;p&gt;Here is a simple representation of my models&lt;/p&gt;

&lt;p&gt;Devise User&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class User
    include Mongoid::Document
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

    ...

    belongs_to :company
    validates :company, presence: true
    validates_associated :company
    accepts_nested_attributes_for :company
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Company model&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Company
    include Mongoid::Document
    field :name, type: String

    has_many :users
        validates :name, presence: true
        validates_uniqueness_of :name, case_sensitive: true, allow_blank: false
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I&amp;rsquo;ve changed new devise registration view&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.container
    = simple_form_for resource, as: resource_name, url: registration_path(resource_name) do |f|
        = f.simple_fields_for :company, resource.company do |company_fields|
            = company_fields.input :name, autofocus: true, as: :string
        = f.input :email, as: :string
        = f.input :password, as: :password
        = f.input :password_confirmation, as: :password
        .form-group
            = f.button :submit
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Devise provide RegistrationController with this new action :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Devise::RegistrationsController &amp;lt; DeviseController
    prepend_before_filter :require_no_authentication, :only =&amp;gt; [ :new, :create, :cancel ]
    prepend_before_filter :authenticate_scope!, :only =&amp;gt; [:edit, :update, :destroy]

    # GET /resource/sign_up
    def new
        build_resource({})
        respond_with self.resource
    end

    ...
 end
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Changes attemps&lt;/h3&gt;

&lt;p&gt;I rely on ActiveModel and nested attributes to build my object from the parameters, so I want to change&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;build_resource ({})
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;for&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;build_resource({ comapny_attributes: {} })
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Show in the console my expectations :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; user = User.new({company_attributes:{}, email:'me@joelazemar.fr', password:'secret', password_confirmation:'secret'})
&amp;gt;&amp;gt; user.company
=&amp;gt; #&amp;lt;Company id: nil, name: nil, created_at: nil, updated_at: nil&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ok great the company has been added to my User and validations can be correctly&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; user.valid?
=&amp;gt; false
&amp;gt;&amp;gt; user.errors.full_messages
=&amp;gt; ["Company is invalid"]
&amp;gt;&amp;gt; user.company.errors.full_messages
=&amp;gt; ["Name can't be blank"]
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Ok now up to the magic of Ruby&lt;/h3&gt;

&lt;p&gt;I want change Registration new action for pre build a new empty resource.company, this will allow me to leave SimpleForm and Rails do their job!&lt;/p&gt;

&lt;p&gt;adding my new wanted action of Registration controller called &amp;lsquo;custom_new&amp;rsquo;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;module DeviseRegistrationsControllerDecorator
    extend ActiveSupport::Concern

    def custom_new
        build_resource({ comapny_attributes: {} })
        respond_with self.resource
    end
end

Devise::RegistrationsController.send(:include, DeviseRegistrationsControllerDecorator)
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Alias and Redefinition&lt;/h3&gt;

&lt;p&gt;Finally, I updated the module so that when it was included, an alias for the core new method, and an override of the core new method with the custom_new method:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;module DeviseRegistrationsControllerDecorator
    extend ActiveSupport::Concern

    included do
        alias :devise_new :new
        def new; custom_new; end
    end

    def custom_new
        ...
    end
end

Devise::RegistrationsController.send(:include, DeviseRegistrationsControllerDecorator)
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Development mode&lt;/h3&gt;

&lt;p&gt;config/environments/development.rb&lt;/p&gt;

&lt;p&gt;Because classes are not cached in development, and library modules are not automatically reloaded, I added the following call to config/environments/development.rb to force a reload of the module to ensure that the devise controller would always be extended:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;config.to_prepare do
    Devise::RegistrationsController.send(:include, DeviseRegistrationsControllerDecorator)
end
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;In this case, ActiveSupport::Concern was used to easily override the core devise method without requiring hacking at the source code. One disadvantage to this implementation is that if significant changes are made to the core method, those changes also need to be applied to the custom controller if necessary.&lt;/p&gt;

&lt;p&gt;Thank you to Steph Skardal and hoping that it may be used to the other.&lt;/p&gt;

&lt;p&gt;Source &lt;a href="http://blog.endpoint.com/2012/06/devise-on-rails-prepopulating-form-data.html"&gt;http://blog.endpoint.com/2012/06/devise-on-rails-prepopulating-form-data.html&lt;/a&gt;&lt;/p&gt;</description><link>http://joelazemar.fr/post/65224324836</link><guid>http://joelazemar.fr/post/65224324836</guid><pubDate>Sun, 27 Oct 2013 13:02:00 +0100</pubDate><category>devise</category></item><item><title>Ruby Thread with Rspec</title><description>&lt;h1&gt;Ruby Thread with Rspec&lt;/h1&gt;

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;One may wish to start the execution of the code so as concurently manner in production or in development mode, but sometimes when you want to pass a test is to be hoped that this code is not executed in parallel but inline to retrieve the correct value in our test . I was personally exposed to it and that&amp;rsquo;s how I do. This is perhaps not the best solution but in my case it&amp;rsquo;s perfectly fulfills its role.&lt;/p&gt;

&lt;h2&gt;Sample&lt;/h2&gt;

&lt;p&gt;Consider a perfectly stupid work but the result is different if the execution is inline or concurently&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sleeper = (1..3).to_a.reverse
['foo', 'bar', 'zone'].each_with_index do |variable, index|
  sleep sleeper[index]
  result &amp;lt;&amp;lt; variable
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;now you want threadify this job&lt;/p&gt;

&lt;p&gt;One way to do that is&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[].tap do |threads|
    sleeper = (1..3).to_a.reverse
    ['foo', 'bar', 'zone'].each_with_index do |variable, index|
        threads &amp;lt;&amp;lt; Thread.new do
            sleep sleeper[index]
            result &amp;lt;&amp;lt; variable
        end
    end
end.each &amp;amp;:join
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The concern here is that the code will no longer execute inline&lt;/p&gt;

&lt;p&gt;Here is the path I took to keep the 2-way&lt;/p&gt;

&lt;p&gt;I wrote an Module&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;module Threadify

  attr_accessor :jobs

  def jobs
    @jobs ||= []
  end

  def prepare async = true
    if async
      thread = asyncronous { yield }
      jobs &amp;lt;&amp;lt; thread
    else
      proc = inline { yield }
      jobs &amp;lt;&amp;lt; proc
    end
  end

  def launch async = true
    async ? jobs.each(&amp;amp;:join) : jobs.each(&amp;amp;:call)
  end

  private

  def asyncronous
    Thread.new { yield }
  end

  def inline
    Proc.new { yield }
  end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In my code I called jobs like that&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Main
  include Threadify

  attr_accessor :result

  def initialize
    @result = []
  end

  def work async = true
    sleeper = (1..3).to_a.reverse
    ['foo', 'bar', 'zone'].each_with_index do |variable, index|
      prepare(async) do
        sleep sleeper[index]
        result &amp;lt;&amp;lt; variable
      end
    end
  end

  def start async = true
    work async
    launch async
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now I can call the code of 2 ways&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;describe 'Sample' do
  subject { Main.new }
  context 'inline' do
    let(:async) { false }
    before { subject.start async }
    it 'should keep order' do
      subject.result.should eql ['foo', 'bar', 'zone']
    end
  end
  context 'async' do
    let(:async) { true }
    before { subject.start async }
    it 'should reverse order' do
      subject.result.should eql ['zone', 'bar', 'foo']
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The code of this sample is &lt;a href="https://github.com/joel/rspec_thread"&gt;here&lt;/a&gt;&lt;/p&gt;</description><link>http://joelazemar.fr/post/53919093789</link><guid>http://joelazemar.fr/post/53919093789</guid><pubDate>Wed, 26 Jun 2013 11:35:14 +0200</pubDate><category>ruby</category><category>rspec</category><category>thread</category></item><item><title>Call Method through collection</title><description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;I had the idea to call an object method through a collection, this is how i did..&lt;/p&gt;

&lt;p&gt;Make a simple Object class person with money method&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Person
  attr_accessor :money
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can pass by a Proc like that&lt;/p&gt;

&lt;p&gt;You grab new instance of John et Bob&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  john, bob = Person.new, Person.new
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Defined Proc set_money&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  set_money = Proc.new do |person, money|
    person.__send__ :money=, money
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And you can iterate on your object collection and call your proc, like that&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  [john, bob].map do |person|
    set_money.call person, rand(100)
  end

  puts "John have #{john.money}$"
  puts "Bob have #{bob.money}$"
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You obtain that&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  =&amp;gt; John have 44$
  =&amp;gt; Bob have 74$
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ok great its cool, but i want go more deeper&amp;hellip;&lt;/p&gt;

&lt;p&gt;You can Monkey Patch Array with method missing like that&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Array

  def method_missing method_name, *args
    self.each do |element|
      raise "undefined method `#{method_name}` for #{element}" unless element.respond_to?(method_name)
      element.public_send(method_name, *args) if element
    end
  end
 end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You start again&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;begin
  john, bob = Person.new, Person.new
  [john, bob].__send__ :money=, 100

  puts "John have #{john.money}$"
  puts "Bob have #{bob.money}$"
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You obtain that&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;=&amp;gt; John have 100$
=&amp;gt; Bob have 100$
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Yeah! It work! Seems look better, no? Ok ok.. NO! It&amp;rsquo;s not a good idea to Monkey Patch Array, but you can make that on different way, look that:&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;m defined a wrapper class, for encapsulate my modified Array Class&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Wrapper &amp;lt; Array

  def self.wrap object
    if object.kind_of? Array
      array = new
      object.each do |element|
        raise 'none recursive array are supported' if element.kind_of? Array
        array &amp;lt;&amp;lt; element
      end
      array
    else
      object
    end
  end

  def method_missing method_name, *args
    self.each do |element|
      element.__send__(method_name, *args) if element &amp;amp;&amp;amp; element.respond_to?(method_name)
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Start again&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;begin
  john, bob = Person.new, Person.new
  Wrapper.wrap([john, bob]).__send__ :money=, 100

  puts "John have #{john.money}$"
  puts "Bob have #{bob.money}$"
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You obtain that&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;=&amp;gt; John have 100$
=&amp;gt; Bob have 100$
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ok it the really good way for that, you can serve to behavior of chosen class without altering for all of your application scope.&lt;/p&gt;</description><link>http://joelazemar.fr/post/51644449204</link><guid>http://joelazemar.fr/post/51644449204</guid><pubDate>Wed, 29 May 2013 16:42:09 +0200</pubDate></item><item><title>Management variables scope for inline conditions by Ruby</title><description>&lt;h1&gt;Management variables scope for inline conditions by Ruby&lt;/h1&gt;

&lt;h2&gt;Classic way&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;class ActiveRelation
    def exists?; true; end
    def first; 'Roger Rabbit'; end
  end

  class PetStore

    def guinea_pig
      if (result = item).exists?
        result.first
      end
    end

    def item
      ActiveRelation.new
    end
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;No problem here&lt;/p&gt;

&lt;p&gt;puts &amp;ldquo;#1 PetStore.new.guinea_pig =&amp;gt; #{PetStore.new.guinea_pig}&amp;rdquo;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#1 PetStore.new.guinea_pig =&amp;gt; Roger Rabbit
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Inline Way&lt;/h2&gt;

&lt;p&gt;Normally the variable should have the same access, if the condition is written inline&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  class PetStore

    def guinea_pig
      result.first if (result = item).exists?
    end

    def item
      ActiveRelation.new
    end
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However, the variable is not available here? :/&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  begin
    puts "#2 PetStore.new.guinea_pig =&amp;gt; #{PetStore.new.guinea_pig}"
  rescue Exception =&amp;gt; e
    puts "#2 #{e.message}"
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Output :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  #2 undefined local variable or method `result' for #&amp;lt;PetStore:0x007fb962909660&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;What happened behind the scene ?&lt;/h2&gt;

&lt;p&gt;In fact Ruby make a Proc for managed inline condition, therefore the variable is not accessible out the box !&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  class PetStore

    def guinea_pig
      if Proc.new { (result = item).exists? }
        result.first
      end
    end

    def item
      ActiveRelation.new
    end
  end

  begin
    puts "#3 PetStore.new.guinea_pig =&amp;gt; #{PetStore.new.guinea_pig}"
  rescue Exception =&amp;gt; e
    puts "#3 #{e.message}"
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Output :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#3 undefined local variable or method `result' for #&amp;lt;PetStore:0x007fb962909660&amp;gt;
&lt;/code&gt;&lt;/pre&gt;</description><link>http://joelazemar.fr/post/48266209319</link><guid>http://joelazemar.fr/post/48266209319</guid><pubDate>Thu, 18 Apr 2013 09:59:00 +0200</pubDate><category>ruby</category><category>variable</category><category>scope</category><category>proc</category></item><item><title>Template Converters ERB =&gt; SLIM</title><description>&lt;h1&gt;How convert your .erb to .slim :&lt;/h1&gt;

&lt;p&gt;You must pass through &lt;em&gt;HAML&lt;/em&gt; !&lt;/p&gt;

&lt;p&gt;Install &lt;em&gt;HAML&lt;/em&gt; dependencies on your environment or your gemset&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem install haml # &lt;a href="https://github.com/haml/haml"&gt;https://github.com/haml/haml&lt;/a&gt;
gem install hpricot
gem install ruby_parser
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Switch to &lt;em&gt;HAML&lt;/em&gt; templating&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;find . -name '*erb' | \
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | \
bash
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Install &lt;em&gt;SLIM&lt;/em&gt; tool dependency&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem install haml2slim # &lt;a href="https://github.com/fredwu/haml2slim"&gt;https://github.com/fredwu/haml2slim&lt;/a&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Switch to &lt;em&gt;SLIM&lt;/em&gt; templating&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;find . -name '*haml' | \
xargs ruby -e 'ARGV.each { |i| puts "haml2slim #{i} #{i.sub(/haml$/,"slim")}"}' | \
bash
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Clean &lt;em&gt;ERB&lt;/em&gt; and &lt;em&gt;HAML&lt;/em&gt; templates&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;find . -name '*erb' -exec rm -f {} \;
find . -name '*haml' -exec rm -f {} \;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Remove dependencies&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem uninstall haml
gem uninstall hpricot
gem uninstall ruby_parser
gem uninstall haml2slim
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That all, have fun&lt;/p&gt;</description><link>http://joelazemar.fr/post/41364702258</link><guid>http://joelazemar.fr/post/41364702258</guid><pubDate>Thu, 24 Jan 2013 17:23:02 +0100</pubDate><category>rails</category><category>template</category><category>erb</category><category>haml</category><category>slim</category><category>convert</category></item><item><title>Application Rails 3.2.9 Without ActiveRecord</title><description>&lt;p&gt;Switch from ActiveRecord from MongoDB through Mongoid&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.flickr.com/photos/13747884@N00/sets/72157632132049960/"&gt;images&lt;/a&gt;&lt;/p&gt;</description><link>http://joelazemar.fr/post/36812775714</link><guid>http://joelazemar.fr/post/36812775714</guid><pubDate>Thu, 29 Nov 2012 17:04:00 +0100</pubDate><category>rails</category><category>active_record</category><category>mongoid</category><category>mongodb</category></item><item><title>Ruby autoload with namespaces</title><description>&lt;p&gt;Simple example of autoload with namespace&lt;/p&gt;

&lt;p&gt;into my file foo_module.rb&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
  puts "i'm loaded"

  module My
    module FooModule
      extend self
    
      # My::FooModule.print
      def print
        puts 'foo'
      end

    end
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In Irb Console try this 2 ways :&lt;/p&gt;

&lt;p&gt;regular way&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
  irb
  &amp;gt;&amp;gt; require './foo_module'
  i'm loaded
  =&amp;gt; true
  &amp;gt;&amp;gt; My::FooModule.print
  foo
  =&amp;gt; nil
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;autoload way :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
  irb
  &amp;gt;&amp;gt; autoload :My, './foo_module'
  =&amp;gt; nil
  &amp;gt;&amp;gt; My::FooModule.print
  i'm loaded
  foo
  =&amp;gt; nil
&lt;/code&gt;&lt;/pre&gt;</description><link>http://joelazemar.fr/post/32872605779</link><guid>http://joelazemar.fr/post/32872605779</guid><pubDate>Thu, 04 Oct 2012 16:32:00 +0200</pubDate><category>ruby</category><category>irb</category><category>autolaod</category></item><item><title>Ruby 1.9.3-p194 and Bundler</title><description>&lt;p&gt;If you update your version of Ruby to &lt;code&gt;Ruby 1.9.3 patch 194&lt;/code&gt; you might to see Rails don&amp;rsquo;t work anymore :(&lt;/p&gt;

&lt;p&gt;The problem is the naming of the file Wrapper Bundler.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;~/.rvm/gems/ruby-1.9.2-p290@global/bin/bundler_wrapper&lt;/code&gt;&lt;br/&gt;&lt;code&gt;~/.rvm/gems/ruby-1.9.3-p194@global/bin/ruby_bundler_wrapper&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Env :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bundler-1.1.3&lt;/code&gt;&lt;br/&gt;&lt;code&gt;rvm 1.13.4&lt;/code&gt;&lt;br/&gt;&lt;code&gt;Rails 3.2.3&lt;/code&gt;&lt;/p&gt;</description><link>http://joelazemar.fr/post/23093994035</link><guid>http://joelazemar.fr/post/23093994035</guid><pubDate>Tue, 15 May 2012 09:24:54 +0200</pubDate><category>rails 3.2</category><category>rvm</category><category>bundler</category><category>bundle</category></item><item><title>Passer sous Ruby 1.9.3-p0 avec RVM</title><description>&lt;p&gt;Mettez à jour la version de RVM =&amp;gt; 1.9.2&lt;br/&gt;&lt;code&gt;$ rvm get latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Mettez à jour la version de RubyGem =&amp;gt; 1.8.11&lt;br/&gt;&lt;code&gt;$ gem update --system&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Enfin installer Ruby 1.9.3&lt;br/&gt;&lt;code&gt;$ rvm install 1.9.3-p0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Ou avec rbenv :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ brew update&lt;/code&gt;&lt;br/&gt;&lt;code&gt;$ brew install rbenv&lt;/code&gt;&lt;br/&gt;&lt;code&gt;$ brew install ruby-build&lt;/code&gt;&lt;br/&gt;&lt;code&gt;$ rbenv install 1.9.3-p0&lt;/code&gt;&lt;br/&gt;&lt;code&gt;$ rbenv global 1.9.3-p0&lt;/code&gt;&lt;/p&gt;</description><link>http://joelazemar.fr/post/12206066139</link><guid>http://joelazemar.fr/post/12206066139</guid><pubDate>Tue, 01 Nov 2011 20:55:00 +0100</pubDate></item><item><title>ImageMagick</title><description>&lt;p&gt;ImageMagick est extrêmement puissant mais n'est pas très simple a utiliser ou du moins les docs me sont étrangement ésotérique.&lt;/p&gt;

&lt;p&gt;Ayant dû manipuler des images je vous livre les commandes.&lt;/p&gt;

&lt;p&gt;Afin de générer un graphique avec un grand nombre d'entrée j'ai du segmenter les envoient à &lt;strong&gt;Google Chart Image&lt;/strong&gt; qui m'a donc renvoyé un morceau de Graphique à chaque appel, afin de livrer un graphique utilisable sur une seule image j'ai dû passer par plusieurs manipulations&lt;/p&gt;

&lt;p&gt;L'image brut :&lt;/p&gt;

&lt;p&gt;&lt;img src="https://lh5.googleusercontent.com/-yNi47l4EIKw/Tlz54m_WhEI/AAAAAAAAAQI/yj6W7_86ml4/s640/g-250h_projection_3_chart_0_image_0.png" alt="Image Brut"/&gt;&lt;/p&gt;

&lt;p&gt;Premièrement supprimer les espaces&lt;/p&gt;

&lt;p&gt;&lt;code&gt;convert image_0.png -crop 300x1000+4+0 image_0_crop.png&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Image cropée :&lt;/p&gt;

&lt;p&gt;&lt;img src="https://lh3.googleusercontent.com/-KkIhwN8HyvM/Tlz54c_l9-I/AAAAAAAAAQA/2edefHrs6bU/s640/g-250h_projection_3_chart_0_image_0_frame.png" alt="Image Cropee"/&gt;&lt;/p&gt;

&lt;p&gt;La taille maximum de l'image renvoyé par &lt;strong&gt;Google Chart Image&lt;/strong&gt; est de 300 000 pixels, afin d'optimiser le nombre de points tracé on ne va pas demander à &lt;strong&gt;Google Chart Image&lt;/strong&gt; de nous ajouter les axes, mais nous allons les faire nous même :&lt;/p&gt;

&lt;p&gt;Pour l'axe des abscisses on va ajouter des images d'axe vierge&lt;/p&gt;

&lt;p&gt;&lt;img src="https://lh5.googleusercontent.com/-rMJOmXimFWw/Tlz_1HssEgI/AAAAAAAAAQw/gciMqET5yE8/s800/Axe300E2.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;puis on va créer l'image horodatée correspondante (Toutes les 10 minutes)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;command = "convert -size 300x60 canvas:none -pointsize 20 -fill black -draw \"text 123,45 '"
command.concat(@date.advance(:minutes =&amp;gt; +(5+(index*10))).strftime(ChartLine::TIME_FORMAT))
command.concat("'\" hour.png")
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;img src="https://lh5.googleusercontent.com/-9DkmadEdbeM/Tlz_n24BG9I/AAAAAAAAAQs/oMG1jCBUVJM/s800/hour.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;Puis on va composer l'image :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;composite hour.png axis_of_x.png axe.png
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;img src="https://lh6.googleusercontent.com/-79tps52HIo8/Tlz_lxcivCI/AAAAAAAAAQo/kqNrqHWFEyA/s800/axe.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;On va coller le graphique dans une frame afin d'ajouter la place pour recevoir l'échelle des abscisses :&lt;/p&gt;

&lt;!-- ![](https://lh5.googleusercontent.com/-Za_ifrPbHRA/Tlz_1fxDy-I/AAAAAAAAAQ8/iTTnD9thkQw/s640/frame.png) --&gt;

&lt;pre&gt;&lt;code&gt;composite -gravity North image_0_crop.png frame.png image_0_frame.png
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;img src="https://lh3.googleusercontent.com/-KkIhwN8HyvM/Tlz54c_l9-I/AAAAAAAAAQA/2edefHrs6bU/s640/g-250h_projection_3_chart_0_image_0_frame.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;Maintenant on peut coller le morceau d'axe d'abscisse au morceau de graphique que nous avons&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;composite -gravity South axe.png frame.png image_0_axis.png
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;img src="https://lh4.googleusercontent.com/-gnnTHm8v8Cg/Tlz55TkuRoI/AAAAAAAAAQU/l65KcKuU_qA/s640/g-250h_projection_3_chart_0_image_1_axis.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;Ceci étant légèrement différent pour la première image car elle doit recevoir en + l'axe des ordonnées :&lt;/p&gt;

&lt;p&gt;Pour cela on choisit une frame un peu plus large&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;composite -gravity East image_0_axis.png first_frame.png image_0_first.png
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;On colle l'axe des ordonnées&lt;/p&gt;

&lt;p&gt;&lt;img src="https://lh6.googleusercontent.com/-he8Of3zMG8c/Tlz_1MHBmdI/AAAAAAAAAQ0/Uff7bCCzwGw/s640/Axe1000E2.png" alt=""/&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;composite -gravity West axis_of_y.png image_0_first.png image_0_axis.png
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;img src="https://lh6.googleusercontent.com/-O8xTEZ3oJJA/Tlz54P_FLFI/AAAAAAAAAP4/SdtoXHrQ1G0/s640/g-250h_projection_3_chart_0_image_0_axis.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;Pour la suite on peut itérer sur toutes les images composées et on les collent :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;convert image1.png image2.png image3.png +append -quality 75 imagefinale.png
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;img src="https://lh5.googleusercontent.com/-dKR9lUbgCgo/Tlz5_a1P1VI/AAAAAAAAAQY/JADHbDPr8n0/s400/g-250h_projection_3_chart_3_append.png" alt=""/&gt;&lt;/p&gt;</description><link>http://joelazemar.fr/post/9588945418</link><guid>http://joelazemar.fr/post/9588945418</guid><pubDate>Tue, 30 Aug 2011 17:52:49 +0200</pubDate><category>imagemagick</category><category>rails</category></item><item><title>Rvm Bundler Rails 3.1 Thin Ubuntu</title><description>&lt;p&gt;Fichier /etc/init.d sous Ubuntu pour démarrer son app dans son environnement propre&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  #! /bin/sh
  ### BEGIN INIT INFO
  # Provides:       &amp;lt;app_name&amp;gt;
  # Required-Start: $syslog
  # Required-Stop:  $syslog
  # Should-Start:       $local_fs
  # Should-Stop:        $local_fs
  # Default-Start:  2 3 4 5
  # Default-Stop:       0 1 6
  # Short-Description:  &amp;lt;app_name&amp;gt; - Site Web
  # Description:        &amp;lt;app_name&amp;gt; - Site Web
  ### END INIT INFO


  PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  DAEMON=$HOME/.rvm/gems/ruby-1.9.2-p180@&amp;lt;app_name&amp;gt;/bin/thin
  DESC="&amp;lt;app_name&amp;gt;"
  NAME=&amp;lt;app_name&amp;gt;_env
  PROJECT_PATH=/var/www/$NAME # env

  check_thin() {
    for i in `ps aux|grep thin|grep '&amp;lt;app_name&amp;gt;.thin'|grep 'sock'|awk '{print $2}'`; 
    do 
        echo "Thin on $i"; 
        sleep 1; 
    done
  }

  test -x $DAEMON || exit 0

  set -e

  case "$1" in
    start)
        echo "Starting $DESC ..."
        rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.2-p180@&amp;lt;app_name&amp;gt;' -c \
        'cd /var/www/&amp;lt;app_name&amp;gt;_env/current/ &amp;amp;&amp;amp; bundle exec thin -C \
        /etc/thin/&amp;lt;app_name&amp;gt;_env.yml start'
        echo "$DESC is started !"
    ;;
    stop)
        echo "Stopping $DESC ..."
        rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.2-p180@&amp;lt;app_name&amp;gt;' -c \
        'cd /var/www/&amp;lt;app_name&amp;gt;_env/current/ &amp;amp;&amp;amp; bundle exec thin -C \
        /etc/thin/&amp;lt;app_name&amp;gt;_env.yml stop'
        echo "$DESC is stopped !"
    ;;
    restart|force-reload)
        echo "Restarting $DESC ..."
        rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.2-p180@&amp;lt;app_name&amp;gt;' -c \
        'cd /var/www/&amp;lt;app_name&amp;gt;_env/current/ &amp;amp;&amp;amp; bundle exec thin -C \
        /etc/thin/&amp;lt;app_name&amp;gt;_env.yml restart'
        echo "$DESC is started !"
    ;;
    status)
        echo "Status"
        check_thin
    ;;
    *)
        N=/etc/init.d/&amp;lt;app_name&amp;gt;
        echo "Usage: $N {start|stop|restart|force-reload|status}" &amp;gt;&amp;amp;2
        exit 1
    ;;
  esac

  exit 0
&lt;/code&gt;&lt;/pre&gt;</description><link>http://joelazemar.fr/post/6256446369</link><guid>http://joelazemar.fr/post/6256446369</guid><pubDate>Mon, 06 Jun 2011 21:25:51 +0200</pubDate><category>rvm</category><category>bundler</category><category>rails 3.1</category><category>thin</category><category>ubuntu</category></item><item><title>Ajouter une api key d'authentification dans toutes les requêtes ActiveResource pour Devise</title><description>&lt;p&gt;J'ai chercher du coté de Rack en middleware pour ajouter les paramètres d'authentification attendu par devise lorsqu'on active l'option :token_authenticatable mais malheureusement je n'ai pas réussi à les ajouter&amp;hellip;&lt;/p&gt;

&lt;p&gt;Cependant j'ai trouvé une solution en surchargeant les méthodes d'ActiveResource&lt;/p&gt;

&lt;p&gt;Ajouter la librairie suivante dans le répertoire /lib/active_resource/extend/ ne pas oublier de dé-commenter le ligne&lt;br/&gt;&lt;em&gt;&amp;ldquo;config.autoload_paths += %W(#{config.root}/lib)&amp;rdquo;&lt;/em&gt; dans config/application.rb&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;module ActiveResource #:nodoc:
  module Extend
    module AuthWithApi
      module ClassMethods
        def element_path_with_auth(*args)
          element_path_without_auth(*args).concat("?auth_token=#{self.api_key}")
        end
        def new_element_path_with_auth(*args)
          new_element_path_without_auth(*args).concat("?auth_token=#{self.api_key}")
        end
        def collection_path_with_auth(*args)
          collection_path_without_auth(*args).concat("?auth_token=#{self.api_key}")
        end
      end

      def self.included(base)
        base.class_eval do
          extend ClassMethods
          class &amp;lt;&amp;lt; self
            alias_method_chain :element_path, :auth
            alias_method_chain :new_element_path, :auth
            alias_method_chain :collection_path, :auth
            attr_accessor :api_key
          end
        end
      end  
    end
  end  
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;dans les modèles il faut inclure le module&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Post &amp;lt; ActiveResource::Base
  include ActiveResource::Extend::AuthWithApi

  self.site = "http://application.localhost.com:3011/"
  self.format = :json

  self.api_key = 'jCxKPj8wJJdOnQJB8ERy'

  schema do
    string  :title
    string  :content
  end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Et le tour est joué !&lt;/p&gt;</description><link>http://joelazemar.fr/post/5831211935</link><guid>http://joelazemar.fr/post/5831211935</guid><pubDate>Wed, 25 May 2011 14:15:00 +0200</pubDate><category>devise</category><category>activeresource</category><category>api</category><category>key</category><category>authentification</category></item><item><title>ActiveResource et Json</title><description>&lt;p&gt;J'ai voulu mettre en place un client ActiveResource qui consomme du :json&lt;/p&gt;

&lt;p&gt;J'ai créé un service de Blog simple&lt;/p&gt;

&lt;p&gt;La migration :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class CreatePosts &amp;lt; ActiveRecord::Migration
  def self.up
    create_table :posts do |t|
      t.string :title
      t.text :content
      t.timestamps
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Le modèle :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Post &amp;lt; ActiveRecord::Base
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Le contrôleur :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class PostsController &amp;lt; ApplicationController

    respond_to :html, :xml, :json

    def index
        @posts = Post.all
        respond_with(@posts)
    end

    def show
        @post = Post.find(params[:id])
        respond_with(@post)
    end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Le client ActiveResource&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Post &amp;lt; ActiveResource::Base

  self.site = "http://application.localhost.com:3011/"
  self.format = :xml

  schema do
    string  :title
    string  :content
  end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Jusque là tout est ok et fonctionne très bien, alors je décide de passer en Json&lt;/p&gt;

&lt;p&gt;Le client ActiveResource&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Post &amp;lt; ActiveResource::Base

    self.site = "http://application.localhost.com:3011/"
    self.format = :json

    schema do
      string  :title
      string  :content
    end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Au moment de lister les posts j'obtiens le message suivant :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ActionController::RoutingError in Posts#index

Showing /.../app/views/posts/index.html.erb where line #... raised:

No route matches { :action=&amp;gt;"show", :controller=&amp;gt;"posts", :id=&amp;gt;
#&amp;lt;Post:... @attributes={"post"=&amp;gt;#&amp;lt;Post:... 
@attributes={"content"=&amp;gt;"...","id"=&amp;gt;1, "title"=&amp;gt;"..."}, 
@prefix_options={}&amp;gt;}, @prefix_options={}&amp;gt;}
Extracted source (around line #...):  
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;En fait le service de Blog renvoit le Json avec le :root comme il se doit, cependant ActiveResource ne le gère pas&amp;hellip;&lt;/p&gt;

&lt;p&gt;Vous devez ajouter la directive suivante dans le client :&lt;/p&gt;

&lt;p&gt;Le modèle :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Post &amp;lt; ActiveRecord::Base
    self.include_root_in_json = false
end
&lt;/code&gt;&lt;/pre&gt;</description><link>http://joelazemar.fr/post/5576560454</link><guid>http://joelazemar.fr/post/5576560454</guid><pubDate>Tue, 17 May 2011 16:41:14 +0200</pubDate></item><item><title>Tous des gros cons ?</title><description>&lt;a href="http://www.korben.info/tous-des-gros-cons.html"&gt;Tous des gros cons ?&lt;/a&gt;: &lt;p&gt;Article intéressant sur la conséquences d'Hadopi (entêtement du gouvernement et des majors)&lt;/p&gt;</description><link>http://joelazemar.fr/post/5094524210</link><guid>http://joelazemar.fr/post/5094524210</guid><pubDate>Sun, 01 May 2011 09:05:58 +0200</pubDate><category>hadopi</category></item><item><title>Application de Checkin</title><description>&lt;p&gt;Voilà une petite application ad hoc pour permettre d'émarger votre présence dans un lieux commun. L'idée vient de l'espace de co-working que je fréquente &lt;a href="http://lacantine-toulouse.org/la-cantine-experimentale"&gt;La Cantine à Toulouse&lt;/a&gt; qui effectue un émargement manuel. Ce qui peut paraitre surprenant ou décevant pour une association qui évolue autour des acteurs du numériques de la région, mais money is money et time is money, en clair il faut non seulement du temps, des ressources mais aussi de l'argent pour mettre en place une application aussi simple que celle-ci et qui ne ramène pas d'argent &amp;hellip; Dur dilemme !&lt;/p&gt;

&lt;p&gt;Ce que fait l'application en quelques points :&lt;/p&gt;

&lt;h2&gt;Connexion&lt;/h2&gt;

&lt;p&gt;Lorsque que le co-worker chargera la page du portail il sera obligé de se connecter, sa connexion peut se faire via la délégation d’authentification, cependant un compte utilisateur devra être créé et la délégation devrait être couplée au compte. Si tel n’est pas le cas l’authentification renverra sur la page de compte.&lt;/p&gt;

&lt;h2&gt;Crédit&lt;/h2&gt;

&lt;p&gt;Le co-worker doit posséder des crédits pour pouvoir émarger. Un crédit permet d’émarger une demi-journée.&lt;/p&gt;

&lt;h2&gt;Émargement&lt;/h2&gt;

&lt;p&gt;Une fois authentifié avec un compte crée le co-worker pourra émarger. Il se verra proposer un écran avec un bouton émarger la matinée ou émargé l’après midi en fonction de l’heure, et une proposition pour l’émargement de la journée directement.
L’émargement aura un état «disponible» et une heure de début et de fin de plage correspondant à la matinée ou l’après midi en cours.&lt;/p&gt;

&lt;h2&gt;Mon Compte&lt;/h2&gt;

&lt;p&gt;Le co-worker pourra visualisé la page de son compte, modifier ses informations, connaitre son solde.&lt;/p&gt;

&lt;h2&gt;Consultations des fiches des co-workers&lt;/h2&gt;

&lt;p&gt;En se connectant au portail de n’importe où le co-worker pourra accéder à l’ensemble des fiches des co-worker inscrit. Il pourra aussi voir les personnes ayant émargées et donc censées être présente dans l’espace de co-working. Cependant afin de limiter l'utilisation des informations à des fins autre que la communication naturelle que le co-working est censé amener les informations visible entre les co-worker se limiterons à la photo et au prénom. Afin d'avoir accès à plus d'informations le co-worker pourra effectuer une demande, si cette demande est accepter les 2 profils pourrons mutuellement avoir accès à l'ensemble de leurs informations.&lt;/p&gt;

&lt;h2&gt;Consultations des co-workers présent&lt;/h2&gt;

&lt;p&gt;Accès a la page des co-workers, un filtre permettra d’afficher les personnes présentes en fonction de la plage horaire.&lt;/p&gt;

&lt;h2&gt;Notification de présence&lt;/h2&gt;

&lt;p&gt;Un co-worker pourra être averti de la présence d'un autre co-worker à La Cantine. Cependant cette fonctionnalité ne sera offerte qu'aux co-workers étant déjà en relation.&lt;/p&gt;

&lt;h2&gt;Scénario&lt;/h2&gt;

&lt;p&gt;Le co-worker est invité à s'authentifier, il est inviter à compléter son compte si cela n'est pas fait, puis il est redirigé sur la page de compte où il peut effectuer son checkin, une fois le checkin il est redirigé sur la tronbinoscope des personnes présente.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;L'application est disponible sur Github, toutes contributions sont les bienvenues !!!&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;&lt;a href="https://github.com/joel/checkin" title="Github Checkin Page"&gt;github.com/joel/checkin&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><link>http://joelazemar.fr/post/4833997324</link><guid>http://joelazemar.fr/post/4833997324</guid><pubDate>Fri, 22 Apr 2011 14:24:00 +0200</pubDate><category>github</category><category>rails</category><category>checkin</category><category>app</category><category>La Cantine</category></item><item><title>Nginx ProxyPass et Url routes générateur _url</title><description>&lt;p&gt;Le problème que j'ai rencontré et que je n'ai qu'en parti résolu avec &lt;em&gt;Nginx&lt;/em&gt; est au moment d'utiliser les helpers des routes _url sous rails &lt;em&gt;Nginx&lt;/em&gt; ne définit l'url entant que host mais fournit le nom de l'upstream à la place.&lt;/p&gt;

&lt;p&gt;Si l'on prend un cas concret voici un fichier de configuration Nginx qui redirige sur un server Thin&lt;/p&gt;

&lt;h1&gt;Fichier de configuration&lt;/h1&gt;

&lt;pre&gt;&lt;code&gt;upstream checkin {
    server  unix:/tmp/checkin.thin.0.sock;
}
# Suppression des www.
server { 
    listen 80; 
    server_name www.checkin.fr; 
    rewrite ^ &lt;a href="http://checkin.fr"&gt;http://checkin.fr&lt;/a&gt;$uri permanent; 
}
server {
  listen 80;
  client_max_body_size 50M;
  # sets the domain[s] that this vhost server requests for
  server_name www.checkin.fr;
  # doc root
  root /var/www/checkin/current/public;
  location / {
    # needed to forward user's IP address to rails
    proxy_set_header  X-Real-IP  $remote_addr;
    # Static cache
        if (-f $request_filename.html) {
      rewrite (.*) $1.html break;
    }
    # Everything else
    if (!-f $request_filename) {
      proxy_pass http://checkin;
      break;
    }
  }
  error_page   500 502 503 504  /500.html;
  location = /500.h&lt;a href="http://www.checkin.fr"&gt;www.checkin.fr&lt;/a&gt;; 
    rewrite ^ http://checkin.fr$uri permanent; 
}
server {
  listen 80;
  client_max_body_size 50M;
  # sets the domain[s] that this vhost server requests for
  server_name &lt;a href="http://www.checkin.fr"&gt;www.checkin.fr&lt;/a&gt;;
  # doc root
  root /var/www/checkin/current/public;
  location / {
    # needed to forward user's IP address to rails
    proxy_set_header  X-Real-IP  $remote_addr;
    # Static cache
        if (-f $request_filename.html) {
      rewrite (.*) $1.html break;
    }
    # Everything else
    if (!-f $request_filename) {
      proxy_pass http://checkin;
      break;
    }
  }
  error_page   500 502 503 504  /500.html;
  location = /500.html {
    root   /var/www/checkin/public;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Et bien votre host sera checkin au lieu checkin.fr&lt;/p&gt;

&lt;p&gt;Pour une la route &lt;em&gt;users_url&lt;/em&gt; vous obtenez &lt;em&gt;http://checkin/users&lt;/em&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;users_url =&amp;gt; http://checkin/users
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Afin de contourner le problème j'ai nommé l'upstream avec le nom de domaine, même si c'est qu'un ersatz de solution ça fonctionne, je ne manquerai pas de mettre à jour ce billet si je trouve la solution&lt;/p&gt;

&lt;h1&gt;Environnement :&lt;/h1&gt;

&lt;pre&gt;&lt;code&gt;nginx -v      
nginx version: nginx/0.8.48
thin --version
thin 1.2.11 codename Bat-Shit Craz
rails --version
Rails 3.0.6
&lt;/code&gt;&lt;/pre&gt;</description><link>http://joelazemar.fr/post/4830769782</link><guid>http://joelazemar.fr/post/4830769782</guid><pubDate>Fri, 22 Apr 2011 09:18:37 +0200</pubDate><category>nginx</category><category>rails route</category><category>rails</category><category>proxy_pass</category></item></channel></rss>