Inherited Resources with Rails 4 and strong parameters

With the release of Rails 4.0.0.beta1 I started an app to test the new features and to see if my favorites gems works fine with the new Rails and the strong parameters, introduced on Rails 4.

First thing: Does't work! But we have a solution for this, a monkey patch! For now.

# MonkeyPatch for Inherited Resources to works with strong parameters and rails 4.0
module InheritedResources  
  module BaseHelpers
    protected
    def build_resource
      get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build, request.get? ? {} : resource_params))
    end

    def update_resource(object, attributes)
      object.update_attributes(attributes)
    end
  end
end  

To make the strong parameters work in your controller using the inherited resources, you need to add a method to filter the params that you want.

def resource_params  
  params.require(:project).permit(:name, :description)
end  

See an example with all controller code here:

class ProjectsController < ApplicationController  
  inherit_resources
  protected
  def resource_params
    params.require(:project).permit(:name, :description)
  end
end  

I believe we'll have a new version of inherited_resources gem when final version of Rails 4 has been released.