Skip to content

Instantly share code, notes, and snippets.

@anitagraham
Last active October 20, 2015 07:29
Show Gist options
  • Save anitagraham/a6d1b14bd10b5737493e to your computer and use it in GitHub Desktop.
Save anitagraham/a6d1b14bd10b5737493e to your computer and use it in GitHub Desktop.
Upgrading from Refinery 2.1 to Refinery 3.0

Upgrading a Refinery app to Refinery3, Rails 4.2#

Remove old config values

  1. DELETE config.whitelist_attributes
  2. DELETE config.mass_assignment_sanitizer
  3. DELETE config.active_record.auto_explain_threshold_in_seconds
  4. CHANGE config.serve_static_assets TO config.serve_static_files
  5. SET config.eager_load TO false (dev and test), true (production)

Add secrets.yml

See the ruby upgrade guide for exact details

In your models and controllers

  1. Remove attr_accessible statements in your models. The controller now specifies which attributes in the params array are 'permitted' to be updated. This also applies to the create action.

  2. Add the attributes as strong parameters in your controller

####Example Before

#app/models/person.rb
...
attr_accessible :name, :title
...

After

#app/controllers/people_controller.rb

def new
  @person = Person.new(person_params)
....

def update
  if @person.update(person_params)
  etc
...
protected
def person_params
  params.require(:person).permitted(:name, :title)
end

Refinery Upgrade

run rails generate refinery:cms --update

(this will run rake db:migrate and rake db:seed)

If you are using Refinerycms-blog

run rake acts_as_taggable_on_engine:install:migrations

Check files that you have over-ridden

Check your app for any Refinery files that you may have over-ridden. Compare them to the new Refinery files

  • Do you still need to override them?
  • Are there changes you need to include in your copy of the file?
  • Is there another way of making your change without overriding? Presenters and Decorators offer better ways to change Refinery's default behaviour.

Refinery::Search changes

In application.rb DELETE

config.to_prepare do
  Refinery.searchable_models = Refinery::Page
end

CREATE config/initializers/refinery/search.rb with an entry similar to the following

#config/initializers/refinery/search.rb
Refinery::Search.configure do |config|
  config.enable_for = ['Refinery::Page']
end

The search route which was refinery.search_path is now refinery.search_root_path More information in refinerycms-search documentation

@stefanspicer
Copy link

This is a great help @anitagraham, thank you. One thing to add (as I'm getting deprecation warnings) is to remove this from the engine.rb:

plugin.activity = {

Also, for admin controllers of an extension, you may want to note that it just needs a def person_params (because crudify will call it)

@stefanspicer
Copy link

I also found that permitted() wasn't working, just permit() works.

@stefanspicer
Copy link

FriendlyId Changes

I don't know how common it is for people to use friendly_id, I use it everywhere. If so, in order to continue allowing .find(id) to work:

friendly_id :title, use: :slugged

needs to become:

friendly_id :title, use: [:slugged, :finders]

There are also some other major changes in friendly_id: https://github.com/norman/friendly_id

@charlesdeb
Copy link

In terms of the config values you mention above that need to be changed you mention config.whitelist_attributes
and
config.mass_assignment_sanitizer.
In my application I don't have these exact config variables. Mine are called config.**actve_record**.whitelist_attributes
and
config.**active_record**.mass_assignment_sanitizer
instead. I presume these are what you actually mean, but can you confirm?

@anitagraham
Copy link
Author

Yes, that's what I mean.

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