Padrino

Upgrading Padrino from 0.11.X to 0.12.0 Guide

This is the step-by-step guide for upgrading from Padrino 0.11.X to 0.12.0! This will review all the breaking changes and modifications made within the new release. blog/2015-02-12-upgrading-padrino-from-0-11-x-to-0-12-0-guide.html.md

Ruby 1.8 Support Dropped

Padrino no longer supports Ruby 1.8.X so please ensure that you are running on at least Ruby 1.9.3 before beginning this upgrade! Note that we recommend using Ruby 2.0 or 2.1.0 with Padrino to ensure compatibility with future versions. Also, Ruby 2.X is faster and more memory efficient. Note that Padrino also requires ActiveSupport >= 3.1 now but currently works best with ActiveSupport 4.

Moneta Caching

Because the caching store system has been completely replaced, we need to make the following changes if you are using the caching module.

First, we need to delete old cache files with rm -rf ./tmp/*. Make sure to delete these old temp files in your project! Also, the syntax for configuring the cache store has changed substantially:

# BEFORE
Padrino.cache = Padrino::Cache::Store::File.new(Padrino.root(tmp, app_name, cache)

# AFTER
Padrino.cache = Padrino::Cache.new(:File, :dir => Padrino.root(tmp, app_name.to_s, cache))

We have also deprecated expires_in in favor of just expires:

get /foo, :cache => true do expires 30  Hello world end

Also the old style of getting and setting values has been deprecated in favor of a new syntax:

# BEFORE
MyApp.cache.set(val, test)
MyApp.cache.get(val)

# AFTER
MyApp.cache[val] = testMyApp.cache[val]

More examples of configuring caching store settings are provided below:

Padrino.cache = Padrino::Cache.new(:LRUHash)

# Keeps cached values in memory
Padrino.cache = Padrino::Cache.new(:Memcached)

# Uses default server at localhost

Padrino.cache = Padrino::Cache.new(:Memcached, 127.0.0.1:11211, :exception_retry_limit => 1)
Padrino.cache = Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance)
Padrino.cache = Padrino::Cache.new(:Redis)

# Uses default server at localhost
Padrino.cache = Padrino::Cache.new(:Redis, :host => 127.0.0.1, :port => 6379, :db => 0)
Padrino.cache = Padrino::Cache.new(:Redis, :backend => redis_instance)
Padrino.cache = Padrino::Cache.new(:Mongo)

# Uses default server at localhost
Padrino.cache = Padrino::Cache.new(:Mongo, :backend => mongo_client_instance)
Padrino.cache = Padrino::Cache.new(:File, :dir => Padrino.root(tmp, app_name.to_s, cache))

You can see full details about the new caching system by checking out the padrino-cache readme!

Rack::Protection and CSRF

We need to rewrite the protection settings within config/apps.rb:

# before
set :protection, true

# after
set :protection, :except => :path_traversal

Once that change has been made, the protections should work as expected.

CSRF Protection

In past Padrino versions, there have been compatibility issues with the excellent better_errors gem that provides a nifty dashboard whenever an exception occurs in development. In this release, we have added an easy way to avoid any issues with the added :except argument when configuring CSRF.

# /app/app.rb
module Foobar
  class App < Padrino::Application
    enable :sessions
    configure :development do
    use BetterErrors::Middleware
    BetterErrors.application_root = PADRINO_ROOT
    set :protect_from_csrf, except: %r{/__better_errors/\d+/\w+\z}
  end
end

Once you've properly setup the :except regex, there shouldn't be any issues. This is also useful for when a Padrino project wants to mount a Sinatra or Rack app.

Slim and Haml Content Blocks

The major template handling rewrite and compatibility update for 0.12.0 requires us to use = instead of - in certain cases when creating templates with tag helpers. (Reference Issues #1442, #1441. For example, before we might have written a form with dashes:

- form_tag /destroy, :class => destroy-form, :method => delete do
  - field_set_tag do
    %p
      = label_tag :username, :class => first
      = text_field_tag :username, :value => params[:username]

Now in 0.12.0, we want to write them with = instead:

= form_tag /destroy, :class => destroy-form, :method => delete do
  = field_set_tag do
    %p
      = label_tag :username, :class => first
      = text_field_tag :username, :value => params[:username]

Note that this is a breaking change and that you should upgrade all your templates to this new format as part of the upgrade process!

Reorder Mounter Apps

The Padrino mounter parsing config/apps.rb was modified substantially with support added for cascading requests. These changes have made the apps list order dependent. In particular, we need to insert the sub-apps for a project before the main app in config/apps.rb:

# config/apps.rb
Padrino.mount("Blog").to('/blog')
Padrino.mount("Forum").to('/forum')
Padrino.mount("MainApp").to('/'') # <-- main app last

Make sure to re-order your apps to put the main app at the bottom otherwise you may run into unexpected routing issues.

Fix URL Routes

We have had some odd and unexpected URL routing ambiguity for quite some time. In 0.12.0 we set out to fix this weirdness. As a result, you need to be aware of places which are using incorrect url routing aliases with url_for. Given this route:

SampleApp.controllers :cap_alerts do
  get :index do
    "hello"
  end
end

The following strictness changes with url should be noted:

# BEFORE
url(:cap_alerts, :index)   #=> "/cap_alerts"
url(:cap, :alerts, :index) #=> "/cap_alerts"
url(:cap, :alerts_index)   #=> "/cap_alerts"

# AFTER
url(:cap_alerts, :index)   #=> "/cap_alerts"
url(:cap, :alerts, :index) #=> UnrecognizedException
url(:cap, :alerts_index)   #=> UnrecognizedException

In general as long as you are accessing the url routes properly, this shouldn't cause any issues.

Updated Route Names

We have also adjusted the route names slightly with this release:

# BEFORE
route.name #=> :cap_alerts_index

# AFTER
route.name #=> :"cap_alerts index"

Adjust Admin login_page Configuration

class Admin < Padrino::Application
  # before
  set :login_page, "/admin/sessions/new"

  # after
  set :login_page, "/sessions/new"

Once you've followed this guide, we hope the transition from 0.11.X to 0.12.0 will be very smooth

Contribute

Please report any issues you encounter with this release! We are working very actively on Padrino and want to make the framework as stable and reliable as possible. That concludes the changelog for this release. As always if you want to keep up with Padrino updates, be sure to follow us on twitter: @padrinorb, join us on IRC at “#padrino” on freenode, open an issue, or discuss on gitter.


Padrino 0.12.4

Two months ago, we released 0.12.3 which introduced a number of improvements to the core codebase and put our 0.12.x branch into a solid place. Today, we are releasing the final iteration on the 0.12.x line which includes a ton of bug fixes and documentation cleanup. The details of this release can be found below. This release paves the road for our 0.13.0 release that will likely follow next with several substantial changes in place. The details of this 0.12.4 release can be found below.

Mounter Supports Rack

The Padrino Mounter has always been one of the cores of our framework and allowed the flexible mounting of many different padrino apps within the same project. This functionality is at the heart of the light modular app architecture that powers Padrino. However, until recently the mounter only worked for Padrino apps. With this release, @namusyaka removed that restriction and now we can map any Rack, Grape or Sinatra app into a Padrino project:

# config/apps.rb
Padrino.mount('SinatraApp', app_file: Padrino.root('sinatra_app/app.rb'))
Padrino.mount('Sample::API', app_file: Padrino.root('api/app.rb'))

We are excited for our router to be that much more flexible going forward towards 1.0!

Fixing Padrino Docs

A few months ago, we were honored to be brought onto the RubyRogues podcast to discuss the Padrino Framework and explain why we think Sinatra and Padrino are a great way to build modern and maintainable ruby web apps and APIs.

However, we recognize that our framework has a challenge. Our Padrino guides are almost all woefully outdated and unmaintained and our website is old and rusty. We are fortunate to have Matthias Gunther working tirelessly on the awesome Padrino Book but we recognize we need to do better. To get things going, we have merged all of our markdown docs into the main padrino code repository.

We realize this is only a small first step and we know that one of the biggest roadblocks to a real 1.0 release is a substantial refresh of our documentation and our website. More updates about this soon. If anyone is interested in helping with the documentation effort, please reach out to us.

Bug Fixes and Miscellaneous

A few deprecation notices:

  • There were issues with the implementation of button_to which require deprecating the old behavior and instead wrapping the content of a given block with the tags

Lots of other bug fixes and code cleanup as usual:

  • FIX #1744 Corrects color support for Windows (@tyabe)
  • FIX #1736 Regression with textarea helper (@ujifgc)
  • FIX #1743 Add a padrino-gen generator for creating new Helpers (@dariocravero)
  • FIX #1746 Avoid reloading the file if its path is not started with Padrino.root (@namusyaka)
  • DELETE deprecated build_object method (@namusyaka)
  • FIX #1752 Don’t set the useformat flag when provides method is called from inline (@namusyaka)
  • FIX #48 Update mailer documentation and sample code (@postmodern)
  • FIX #1752 Refactor routing code to avoid weird parameter (@namusyaka)
  • FIX #1754 Adds end tags to admin erb template for index (@namusyaka)
  • FIX #1749 Replace the AR::ConnectionManagement middleware with new middleware (@namusyaka)
  • NEW #1756 Adds support for mysql2 gem in sql rake task helpers (@d6rkaiz)
  • FIX #1761 Allow passing upcased string as the app name
  • FIX #1776 improve params filtering for routes (@ujifgc)
  • FIX #1778 Various YARD doc inconsistencies or errors (@claudiob)
  • FIX #1765 Use controller’s base path instead of constant name at controller test (@namusyaka)
  • FIX #1781 Removes the default_filters method setting incorrect content-type (@namusyaka)
  • FIX Sinatra compatibility for passing options to the static! method
  • FIX #1585 Update HAML to pass tests by upgrading versions (@ujifgc)
  • FIX #1782 make padrino-gen detect absolute paths on Windows (@ujifgc)
  • FIX #1779 Use expanded path to request controller’s content (@namusyaka)
  • FIX Use yield and flatmap when possible to speed up performance (@ujifgc)
  • FIX #1788 exception that occurs when the free regex route exists (@namusyaka)
  • NEW Merges the padrino-docs guides and content directly into the main repository (@ujifgc)

Want to give a special thanks to the key contributors for this release, working tirelessly to make this Padrino release possible: @namusyaka, @ujifgc, @dariocravero and all the other contributors to this version!

Please do report any issues you have. We are working very actively on Padrino and want to make the framework as stable and reliable as possible. That concludes the changelog for this release. As always if you want to keep up with Padrino updates, be sure to follow us on twitter: @padrinorb, join us on IRC at “#padrino” on freenode or open an issue on GitHub.

Contribute

Please report any issues you encounter with this release! We are working very actively on Padrino and want to make the framework as stable and reliable as possible. That concludes the changelog for this release. As always if you want to keep up with Padrino updates, be sure to follow us on twitter: @padrinorb, join us on IRC at “#padrino” on freenode, open an issue, or discuss on gitter.


  • Prev Page
  • Next Page