Upgrade to Rails 4

I have tried to convert my first Rails 3 app to Rails 4. I followed roughly the instructions on edge guides.

The most work i had on reworking the attraccessible that are now removed in rails 4. It is quite easy to migrate, if oyu have e.g. this line in your Model:

attraccessible :name, :email

And you create your model like

Then you just  have to remove the line in the model and change the line in the controller to something like:



def userparams

    params.require(:user).permit(:name, :email)

and that is all.

I also needed to add config.eagerload to the environment configs. Rails 4 is also threadsafe by default if config.eagerload and config.cacheclasses are true.

You need to add
via: [:get, :post]
to all routes that use the match keyword. If it is just a post or get use the appropriate type directly.

I also  added this gems:
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem ‘turbolinks’

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem ‘jbuilder’, ‘~> 1.0.1’

After that i deployed it with capistrano and got an error regarding the asset pipeline. Luckily there was also link explaining what to do. It is from capistrano to upgrade the asset pipeline. This part was helping me:

“Recent versions of Capistrano backup this file to the release directory during each deploy. Please confirm that your current Rails 3.x release directory contains an assetsmanifest.yml in its root. If it does, then it is safe to remove the manifest.yml file in your assets directory. If it does not exist, you should move your manifest.yml file to your current release’s root directory and name it assets_manifest.yml. Should you need to roll back your Rails 4 deploy, Capistrano will restore it for you.”

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *