Rails 4 support #200

wants to merge 19 commits into


None yet
9 participants


This pull-request adds Rails 4 support.

Please see commit messages for detailed changes.

Please let me know if you have any questions. I will be glad to answer.


ernie commented Feb 14, 2013


  • Polyamorous dependency will need to be updated to ~> 0.6.0
  • Unless something drastic has changed, we didn't stop supporting 3.0/3.1. We shouldn't be tolerating fails in those versions, should we?

Thanks, I have updated polyamorous dependency to ~> 0.6.0

In re failing specs, indeed we should not tolerate them. I will take a look at them as I have time even though they are not related to this pull-request. I tend to think it should be a separate pull-request.

Oh yeah, "missing require" commit fixes 3-1-stable specs.

All tests pass now. Please see commit message for explanation what was wrong with last set of tests.

At first it was assumption, that 3-0-stable and 3-1-stable+ generates links differently, but then I created two sample apps (3-0-stable and 3-1-stable) and confirmed this.

zolzaya commented Apr 24, 2013



jonatack commented Apr 24, 2013

If anyone is on Edge Rails, here is a fork of Ransack (https://github.com/jonatack/ransack) that is currently compatible with Edge Rails only. You'll need to upgrade to Polyamorous 0.6.2, which Ernie just updated.

Ransack's Rails-4 branch was broken by this Edge Rails commit on April 10.

Hey guys,

I'm completely new to Ransack. Tried the following code in Rails 4 Beta 1 and it crashed upon hitting the submit button:

# Error message
Don't know how to klassify #<ActiveRecord::Associations::JoinDependency::JoinBase:0x007ffdf6810ca8>
@search = Resource.search(params[:q])

# controller
def index
  @search = Resource.search(params[:q])
  @resources = @search.result(:distinct => true)

# view (HAML)
= search_form_for @search do |f|
    = f.label :title_eq, "Title"
    = f.text_field :title_eq
    = f.submit "Search"

# Gemfile
gem "ransack", :git => "https://github.com/jonatack/ransack"

# Gemfile.lock
polyamorous (0.6.2)
  activerecord (>= 3.0)

What went wrong?


jonatack commented Apr 26, 2013

Hi Michael, for Rails 4 beta1 use the Rails-4 branch here on ernie/ransack.

My fork (that you are using in your code above) is for edge Rails.

Thanks heaps, this did the trick.

gem 'rails', '4.0.0.rc1'
gem 'ransack', git: 'git://github.com/ernie/ransack.git' , branch: 'rails-4'

and I have the same issue with michaelimstepf


jonatack commented May 11, 2013

You can use my fork of Ransack (https://github.com/jonatack/ransack) that is currently compatible with Rails 4.1.0.beta and 4.0.0.rc1, but not 4.0.0.beta nor 3.x. You'll need to upgrade to Polyamorous 0.6.2, which Ernie updated for Rails 4, or my version below which is only for 4.1.0.beta or 4.0.0.rc1.

In your Gemfile:
gem 'ransack', github: 'jonatack/ransack', ref: '0703144bb0ce2ea1884ef02b52bc51157152b566'
gem 'polyamorous', github: 'jonatack/polyamorous', ref: '062c78be2edadfe5fbb104fe68d213fcbeae478d'

Ransack's Rails-4 branch was broken by this Edge Rails commit on April 10.


killthekitten commented May 20, 2013

Currently we have rails-4 branch up-to-date with @jonatack's repo. Should we close this PR (also, #227 and #229)?


jonatack commented May 21, 2013

Yes, the ransack fork on my repo is currently working for Rails 4, but on ernie/ransack/rails-4 I am still getting an active_record dependency conflict and 3.x isn't supported yet. @spectator proposed some changes above that may address that.

spectator added some commits Feb 14, 2013

@spectator spectator Update gemspec to include Rails 4. ccd6529
@spectator spectator X:ActiveModel::Name is not a string in Rails 4, so convert it to stri…
…ng explicitly to cll underscore.

Might be good to encapsulate this in another method so we don't have to change this behavior in >10 places.
@spectator spectator Get rid of deprecation warning, match now requires HTTP method to be …
…explicitly set.
@spectator spectator Remove deprecation warning by using silence_stream instead of AR::Bas…
@spectator spectator 3.0.2 requirement doesn't let run tests on 3-0-stable and 3-1-stable,…
… so remove it
@spectator spectator Use unreleased polyamorous gem with Rails 4 fixes. 9b6067b
@spectator spectator Kill some whitespaces. 232ed1c
@spectator spectator * Add rails 3.2 context and default context for edge rails
* Add relation_for method to return relation correctly (rails 3.0-3.2 wants #scoped, edge rails wants #all)
@spectator spectator Fix deprecation warnings in specs. 7c4b042
@spectator spectator Use latest (rails 4 compatible) polyamorous version. cdc069f
@spectator spectator Add missing require. 822e304
@spectator spectator Ruby 1.8 hash syntax, fixes builds on ruby18, ree, rbx-18mode f7980eb
@spectator spectator Match whether %5B or \[ for `[` and %5D or \] for `]`
It seems that rails 3-0-stable doesn't escape such entities in the URL, all
other versions above do.

I don't think we want to fix rails 3-0 behaviour specifically for ransack.
@spectator spectator Fix incorrectly resolved merge. 535a778
@spectator spectator columns_hash expects table as argument now. 3033738
@spectator spectator active_record was renamed to base_klass c8b5e1b

I did some small updates to my branch so it now works with 4.0 (rc) and 4.1 (master)

Please be aware that there is one failing spec on 3.2


  1) Ransack::Search#sorts= overrides existing sort
     Failure/Error: @s.result.first.id.should eq 1

       expected: 1
            got: 332

       (compared using ==)
     # ./spec/ransack/search_spec.rb:223:in `block (3 levels) in <module:Ransack>'

This is either bad merge or something got broken in master. I did not investigate further yet.

All specs for all versions now pass.

spectator added some commits May 22, 2013

@spectator spectator Redefine relation_for to use `all` instead of deprecated `scoped`. a325465
@spectator spectator Remove duplicated code.
inheritance that is already in place to define it just once.

Conditional in the method also make it easy to support rails 4.

jonatack commented May 23, 2013

Great @spectator. Working through the conflicts to merge it in.

jonatack closed this May 23, 2013

Hi there,
Getting this error "Could not fetch specs from https://rubygems.org/" on adding

gem 'ransack', github: 'jonatack/ransack', ref: '0703144bb0ce2ea1884ef02b52bc51157152b566'
gem 'polyamorous', github: 'jonatack/polyamorous', ref: '062c78be2edadfe5fbb104fe68d213fcbeae478d' to my gem file and running bundle
Using rails 4rc1. Any help?


jonatack commented Jun 3, 2013

The rails-4 branch here on ernie/ransack should be currently working on all versions of Rails 3 and 4.

You can still use my repo for Rails master branch (edge rails / 4.1.0.beta), but it is no longer compatible with 4rc1 because of breaking changes recently in ActiveRecord that affected the Polyamorous gem. I updated Polyamorous in my repo to stay compatible with Rails master and so jonatack/polyamorous is probably no longer working with 4rc1. You'd want to use the original Polyamorous gem in 'ernie/polyamorous' for 4rc1.

In short, for Rails master / 4.1.0.beta:

gem 'ransack', github: 'jonatack/ransack'
gem 'polyamorous', github: 'jonatack/polyamorous'

And for Rails 4.0.0rc1:

gem 'ransack', branch: 'rails-4'
gem 'polyamorous''

rilian commented Jun 3, 2013

@abhishekcol there is an issue on rubygems side at the moment. Does your project load all other gems fine ?

@rilian Yes. It is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment