padrino/padrino-framework — pull request #1786 by wikimatze (2014-10-10 14:05:37+00:00)
Title: New Padrino generator command for creating observers

I stumbled across this missing feature during writing on my book about the observer section .

You just have to call either `padrino g observer ` or `padrino-gen observer ` and it will create a file in `app/models/.rb`.

So this is basically the command for creating new observers.

In order to use `observers`, you have to add the following in the `Gemfile`:

```ruby
gem 'activerecord', '~> 3.2', :require => 'active_record'
```

As well as activate observers in `app/app.rb`:

```ruby
module Test
class App < Padrino::Application
use ActiveRecord::ConnectionAdapters::ConnectionManagement
...

enable :sessions

# Activating the user_observer
ActiveRecord::Base.add_observer UserObserver.instance
end
end
```

I uploaded an example app under so that you can play around with it.

If you are having an observer-file with the right model name, Padrino gives us a nice error message of the form: `ERROR - NameError - uninitialized constant User:`. If there are any tests missing or I forget to add another case, please let me know.

Bests,

Matthias