treehouse-rails is a Rails engine with middleware for Treehouse authentication
Add this line to your application's Gemfile:
$ gem 'treehouse-rails', git: '[email protected]:printreleaf/treehouse-rails'
And then execute:
$ bundle
Create config/initializers/treehouse.rb
:
Treehouse.configure do |config|
config.url = "http://yourtreehouse.com"
config.key = "your-treehouse-key"
config.cookie = "_treehouse_session"
end
Treehouse adds its session to the Rack environment hash so Rails and other Rack applications can interact with it:
session = request.env[:treehouse] #=> #<Treehouse::Session:0x007f8610411a48>
session.logged_in? #=> true
login = session.current_login #=> #<Treehouse::Login:0x007f860efc3208>
login.id #=> 123
login.email #=> "[email protected]"
When Treehouse is in dummy mode, #current_login
will always return a dummy instance of Treehouse::Login
:
Treehouse.configure do |config|
config.dummy = true
end
request.env[:treehouse].current_login #=> #<Treehouse::Login:0x007f860efc3208 @id=123, @email="[email protected]">
It can be helpful to enable dummy mode in development:
Treehouse.configure do |config|
config.dummy = Rails.env.development?
end
$ rspec spec
- Fork it ( https://github.com/printreleaf/treehouse-rails/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
MIT