Skip to content

niklas/ember-rails-flash

Repository files navigation

EmberRailsFlash

Make Rails' flash messages available to Ember.js applications. Inspired by a Blog post by Stefan Siebel.

Installation

Gem

Add the ember-rails-flash gem to your Gemfile (not released as .gem file yet).

gem 'ember-rails-flash'

Controllers

Include EmberRailsFlash::FlashInHeader in (all) the controller(s) dealing with Ember.js. ApplicationController is totally fine.

class ApplicationController < ActionController::Base
  # ...
  include EmberRailsFlash::FlashInHeader
end

Asset Pipeline

Add the javascripts to your asset pipeline (for example application.js), preferrably after ember itself.

//= require handlebars
//= require ember
//= require ember-rails-flash

Ember.js

Now, you can use the provided view directly in your templates or extend them.

MyApp.Messages = Ember.Rails.FlashListView.extend
  fnord: (->
    @get('content').fnordify()
  ).property('content')
  itemViewClass: Ember.View.extend(template: "...")
<h1>My new App</h1>
{{view MyApp.Messages}}

Enable flash messages for JSON responses

If you use the responders gem (which you do if you use the inherited_resources gem), you may want to enable the FlashResponder. If you don't, the expected i_h flash messages will no be set on respond formats other than "html". So for example in config/initializers/flash.rb:

EmberRailsFlash.enable_flash_responder 'json'

ember-cli

First, install this repo throw bower:

ember install:bower https://github.com/niklas/ember-rails-flash.git

Then, just load the provided js from dist/ in your application's Brocfile.

// to compile the inline template
app.import('bower_components/ember/ember-template-compiler.js');
app.import('bower_components/ember-rails-flash/dist/ember-rails-flash.js');

FAQ

Where are your tests?

Tests? What the frak are tests? - Will come .. soon.. ish

Coffeescript? Why?

I love CoffeeScript as it keeps the bad parts out of my JS.

This is not the way to write Ember.js related plugins

I really don't know a better way. If you have one, please send me a pull request :)

You are using Ember.js wrong!

Still learning, please educate me - SRSLY.

Contributing

Feel free to open an issue ticket if you find something that could be improved.

This project rocks and uses GPL-3 as license.

About

Rails' flash messages for Ember.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published