Git Product home page Git Product logo

ember-rails's Introduction

ember-rails Build Status Dependency Status Code Climate

ember-rails makes developing an Ember.JS application much easier in Rails 4.2+.

The following functionalities are included in this gem:

  • Pre-compiling of your handlebars templates when building your asset pipeline.
  • Inclusion of development and production copies of Ember, Ember Data and Handlebars.
  • Inclusion of ActiveModel::Serializer for integration with Ember Data.

You can see an example of how to use the gem here. There is also a great tutorial by Dan Gebhardt called "Beginning Ember.js on Rails" which is a great read if you're just starting out with Rails and Ember.js.

Getting started

  • Add the gem to your application Gemfile:
gem 'ember-rails'
# gem 'ember-source' # You can specify the Ember.js version you want to use.(such as '~> 1.13.0')
  • Run bundle install
  • Next, generate the application structure:
$ rails generate ember:bootstrap
  • Restart your server (if it's running)

Building a new project from scratch

Rails supports the ability to build projects from a template source ruby file.

To build an Ember centric Rails project you can simply type the following into your command line:

$ rails new my-app -m https://emberjs.com/edge_template.rb

Read more about Rails application templates and take a look at the edge_template.rb source code.

Notes:

To install the latest builds of ember and ember-data. It should be noted that the examples in the getting started guide have been designed to use the released version of ember:

$ rails generate ember:install

You'll probably need to clear out your cache after doing this with:

$ rake tmp:clear

Also, ember-rails includes some flags for the bootstrap generator:

--ember-path or -d   # custom ember path
--skip-git or -g     # skip git keeps
--javascript-engine  # engine for javascript (js, coffee, em or es6)
--app-name or -n     # custom ember app name

For CoffeeScript support

Add coffee-rails to the Gemfile

gem 'coffee-rails'

Run the bootstrap generator in step 4 with an extra flag instead:

$ rails g ember:bootstrap -g --javascript-engine coffee

For EmberScript support

EmberScript is a dialect of CoffeeScript with extra support for computed properties (which do not have to be explicitly declared), the class / extends syntax, and extra syntax to support observers and mixins.

To get EmberScript support, make sure you have the following in your Gemfile:

gem 'ember_script-rails', :github => 'ghempton/ember-script-rails'

You can now use the flag --javascript-engine=em to specify EmberScript assets in your generators, but all of the generators will default to using an EmberScript variant first.

For ES6 support

Ember.js recommends using ES6 syntax. It is supported by Babel via ember-es6_template.

Run the bootstrap generator with an extra flag:

$ rails g ember:bootstrap --javascript-engine=es6

Note:

To use ES6 module in your application, the following configuration is required:

Single Ember Application

This is the case for single Ember application in app/assets/javascripts (not under the subdirectory).

my-app.es6

import Application from 'ember-rails/application';

const App = Application.extend({
  // Configure your application.
});

App.create();

import Application from 'ember-rails/application'; and Application.extend() is important. It provides customized Ember application to resolve dependencies from ES6 modules instead of Ember.Application.extend().

application.js

//= require jquery
//= require ember
//= require ember-data
//= require ember-rails/application
//= require ./my-app
//= require_self

require('my-app'); // Run your Ember.js application

Multiple Ember Application

This is the case for multiple Ember application in your Rails application. (Or your Ember application is placed in sub directories of app/assets/javascripts.)

First, you should configure config.ember.module_prefix to nil. To disable prepending the module prefix to you modules.

config/application.rb

config.ember.module_prefix = nil

Second, please specify modulePrefix to your Ember application.

my-app/application.module.es6

import Application from 'ember-rails/application';
import loadInitializers from 'ember/load-initializers';

const App = Application.extend({
  modulePrefix: 'my-app' // This value should be the same as directory name.
});

loadInitializers(App, 'my-app');

App.create();

Last, add your endpoint to where you want to run your Ember application.

require('my-app'); // Run your Ember.js application

Configuration Options

The following options are available for configuration in your application or environment-level config files (config/application.rb, config/environments/development.rb, etc.):

Configuration Option Description
config.ember.variant Determines which Ember variant to use. Valid options: :development, :production. Defaults to :production in production, and :development everywhere else.
config.ember.app_name Specificies a default application name for all generators.
config.ember.ember_path Specifies a default custom root path for all generators.
config.ember.module_prefix Sets module prefix for es6 module. This option is used for only es6 scripts. Default value: ember-app.
config.ember.prefix_files Sets some file names to add config.ember.module_prefix into its file name as es6 module name.
config.ember.prefix_dirs Sets some dir names to add config.ember.module_prefix into its directory name as es6 module name.
config.handlebars.precompile Enables or disables precompilation. Default value: true.
config.handlebars.templates_root Sets the root path (under app/assets/javascripts) for templates to be looked up in. Default value: "templates".
config.handlebars.templates_path_separator The path separator to use for templates. Default value: '/'.
config.handlebars.output_type Configures the style of output (options are :amd and :global). Default value: :global.
config.handlebars.amd_namespace Configures the module prefix for AMD formatted output. Default value: nil.
config.handlebars.ember_template Default which Ember template type to compile. Valid options: 'Handlebars', HTMLBars. Defaults to 'Handlebars' when Ember::VERSION is under 1.10.0, HTMLBars when Ember::VERSION is over 1.10.0.

Note:

In a mountable engine, ember-rails will not recognize any configurations. Instead, use command line options.

Enabling Features with Feature Flags

See the guide and check features.json for the version of Ember you're using.

If a feature is set to false, you will need to compile ember from source yourself to include it.

Important note for projects that render JSON responses

ember-rails includes active_model_serializers which affects how ActiveModel and ActiveRecord objects get serialized to JSON, such as when using render json: or respond_with. By default active_model_serializers adds root elements to these responses (such as adding {"posts": [...]} for render json: @posts) which will affect the structure of your JSON responses.

To disable this effect on your JSON responses, put this in an initializer:

# Stop active_model_serializers from adding root elements to JSON responses.
ActiveModel::Serializer.root = false
ActiveModel::ArraySerializer.root = false

See the active_model_serializers documentation for a more complete understanding of other effects this dependency might have on your app.

Architecture

Ember does not require an organized file structure. However, ember-rails allows you to use rails g ember:bootstrap to create the following directory structure under app/assets/javascripts:

├── adapters
├── components
├── controllers
├── helpers
├── mixins
├── models
├── practicality.coffee
├── router.coffee
├── routes
├── templates
│   └── components
└── views

Additionally, it will add the following lines to app/assets/javascripts/application.js. By default, it uses the Rails Application's name and creates an rails_app_name.js file to set up application namespace and initial requires:

//= require ember
//= require ember-data
//= require_self
//= require rails_app_name
RailsAppName = Ember.Application.create();

Example:

$ rails g ember:bootstrap
  insert  app/assets/javascripts/application.js
  create  app/assets/javascripts/models
  create  app/assets/javascripts/models/.gitkeep
  create  app/assets/javascripts/controllers
  create  app/assets/javascripts/controllers/.gitkeep
  create  app/assets/javascripts/views
  create  app/assets/javascripts/views/.gitkeep
  create  app/assets/javascripts/helpers
  create  app/assets/javascripts/helpers/.gitkeep
  create  app/assets/javascripts/components
  create  app/assets/javascripts/components/.gitkeep
  create  app/assets/javascripts/templates
  create  app/assets/javascripts/templates/.gitkeep
  create  app/assets/javascripts/templates/components
  create  app/assets/javascripts/templates/components/.gitkeep
  create  app/assets/javascripts/mixins
  create  app/assets/javascripts/mixins/.gitkeep
  create  app/assets/javascripts/adapters
  create  app/assets/javascripts/adapters/.gitkeep
  create  app/assets/javascripts/app.js

If you want to avoid .gitkeep files, use the skip git option like this: rails g ember:bootstrap -g.

Ask Rails to serve HandlebarsJS and pre-compile templates to Ember by putting each template in a dedicated ".hbs", ".js.hjs" or ".handlebars" file (e.g. app/assets/javascripts/templates/admin_panel.hbs) and including the assets in your layout:

<%= javascript_include_tag "templates/admin_panel" %>

If you want to avoid the templates prefix, set the templates_root option in your application configuration block:

config.handlebars.templates_root = 'ember_templates'

If you store templates in a file like app/assets/javascripts/ember_templates/admin_panel.hbs after setting the above config, it will be made available to Ember as the admin_panel template.

(Note: you must clear the local sprockets cache after modifying templates_root, stored by default in tmp/cache/assets)

Default behavior for ember-rails is to precompile handlebars templates. If you don't want this behavior you can turn it off in your application configuration (or per environment in: config/environments/development.rb) block:

config.handlebars.precompile = false

(Note: you must clear the local sprockets cache if you disable precompilation, stored by default in tmp/cache/assets)

Bundle all templates together thanks to Sprockets, e.g create app/assets/javascripts/templates/all.js with:

//= require_tree .

Now a single line in the layout loads everything:

<%= javascript_include_tag "templates/all" %>

Note about ember components

When necessary, ember-rails adheres to a conventional folder structure. To create an ember component you must define the handlebars file inside the components folder under the templates folder of your project to properly register your handlebars component file.

Example

Given the following folder structure:

├── adapters
├── components
├── controllers
├── helpers
├── mixins
├── models
├── practicality.coffee
├── router.coffee
├── routes
├── templates
│   └── components
│       └── my-component.hbs
└── views

and a my-component.hbs file with the following contents:

<h1>My Component</h1>

It will produce the following handlebars output:

<script type="text/x-handlebars" id="components/my-component">
  <h1>My Component</h1>
</script>

You can reference your component inside your other handlebars template files by the handlebars file name:

{{ my-component }}

Specifying Different Versions of Ember/Handlebars/Ember-Data

By default, ember-rails ships with the latest version of Ember, Handlebars, and Ember-Data.

To specify a different version that'll be used for both template precompilation and serving to the browser, you can specify the desired version of one of the above-linked gems in the Gemfile, e.g.:

gem 'ember-source', '~> 1.13.0'

You can also specify versions of 'handlebars-source' and 'ember-data-source', but note that an appropriate 'handlebars-source' will be automatically chosen depending on the version of 'ember-source' that's specified.

You can also override the specific ember.js, handlebars.js, and ember-data.js files that'll be required by the Asset pipeline by placing these files in vendor/assets/ember/development and vendor/assets/ember/production, depending on the config.ember.variant you've specified in your app's configuration, e.g.:

config.ember.variant = :production
# config.ember.variant = :development

Updating Ember

If at any point you need to update Ember.js from any of the release channels, you can do that with

$ rails generate ember:install --channel=<channel>

This will fetch both Ember.js and Ember Data from http://builds.emberjs.com/ and copy to the right directory. You can choose between the following channels:

  • canary - This references the 'master' branch and is not recommended for production use.
  • beta - This references the 'beta' branch, and will ultimately become the next stable version. It is not recommended for production use.
  • release - This references the 'stable' branch, and is recommended for production use.

When you don't specify a channel, the release channel is used.

It is also possible to download a specific tagged release. To do this, use the following syntax:

$ rails generate ember:install --tag=v1.13.0 --ember

or for ember-data

$ rails generate ember:install --tag=v1.13.0 --ember-data

CSRF Token

Rails protect_from_forgery requires CSRF token for every XHR except GET. The CSRF token is normally found in app/views/layouts/application.html.* inserted with the rails helper: csrf_meta_tags.

When you use jquery-ujs, the CSRF token will be sent to the rails application on every XHR automatically. If not so, the following JavaScript is required in your code.

$.ajaxPrefilter(function(options, originalOptions, xhr) {
  var token = $('meta[name="csrf-token"]').attr('content');
  xhr.setRequestHeader('X-CSRF-Token', token);
});

Note on Patches/Pull Requests

  1. Fork the project.
  2. Make your feature addition or bug fix.
  3. Add tests for it. This is important so I don't break it in a future version unintentionally.
  4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  5. Send me a pull request. Bonus points for topic branches.

ember-rails's People

Contributors

ashrafmajdee avatar ayarulin avatar defkode avatar duggiefresh avatar eccegordo avatar fivetanley avatar fotinakis avatar ghempton avatar htwroclau avatar indirect avatar jimmay5469 avatar joliss avatar keithpitt avatar knomedia avatar koriroys avatar lukemelia avatar machty avatar michiel avatar mtylty avatar patr1ck avatar robmonie avatar rwjblue avatar stefanpenner avatar tchak avatar tomdale avatar tricknotes avatar tspacek avatar ugisozols avatar wagenet avatar wycats avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-rails's Issues

Use Ember.Handlebars.precompile

There's a precompile function defined in ember-precompiler.js. Ember includes a precompile function: Ember.Handlebars.precompile.

Barber extraction broke config.ember.ember_location

This relates both to ember-rails and barber,

Barber needs a way to specify both ember and handlebar locations, ember-rails needs a way to support custom handlebar and ember locations, both for normal usage and for precompiles.

At the moment config.ember.ember_location is broken.

Generator does not work in rails 3.2.2

I installed the gem with bundler but there is no Generator:

Installing ember-rails (0.2.4)
Your bundle is complete! Use bundle show [gemname] to see where a bundled gem is installed.
rails g ember_rails:bootstrap
Could not find generator ember_rails:bootstrap.

Should ship with fixed dependencies.

I'm trying Ember Rails and it seems that when I try to load in Ember itself it complains about JQuery (in jquery-rails) being version 1.8 rather than 1.7. So, had to look up a more recent version of jquery-rails (version = 2.0.3) which fixed that issue. Next issue is that it was complaining about handlebars (which it ships with the gem?) saying that it has to be version >= 1.0.5.beta (or something). So there were basically 2 dependency JS dependency issue going on and it took some time to figure out which version of jquery-rails was necessary, and I just got the most recent handlebars.js from the official site and dropped it in my vendor. I thought of just removing the gem but it appears that it's still useful for handlebars in the asset pipeline.

Maybe I'm doing something wrong, but I simply tried using the latest gem (and then the repositories HEAD) on a bare Rails app but couldn't get it to work without manually dropping in specific versions of jQuery and Handlebars.js.

If Ember.js is going to complain about specific jQuery versions, maybe it's useful, since Rails always ships with jquery-rails, to add the jquery-rails, = 2.0.3 to the dependency list? This would then use jQuery 1.7.x from what I can see. Also, I guess for Handlebars.js, just drop in the latest version of it to replace whatever version is currently being used.

ember generator

I wrote a rails generator to create Ember models from Rails models. Would you be interested in incorporating it into this project?

Rewire generators in preparation for the new router.

Can someone start a new branch called new-router? I have created an additional generator for generating route_handlers and modified the generated routes file accordingly, and though it is probably not a good idea to pull this into master, it may be a decent idea to have something sitting on another branch.

Uncaught TypeError: Cannot call method 'extend' of undefined

Has any seen this error using ember-rails-0.6.0 and rails g ember:bootstrap?

After it generates the files, when I start my app, I get:
Uncaught TypeError: Cannot call method 'extend' of undefined

Which comes from:

Appname.ApplicationController = Ember.ObjectController.extend({
// Implement your controller here.
});

Issues with rails g ember:install

Running "rails g ember:install" does not install ember.js files into "vendor/assets/ember" as expected.
Running "rails g ember:install --head" does place the ember.js files into "vedor/assets/ember"

To reproduce:

  1. rails new ember-rails-test (with rails version '3.2.8')
  2. add "gem 'ember-rails', github: 'emberjs/ember-rails'" to GemFile
  3. run "bundle install"
  4. add "config.ember.variant = :development" to development.rb
  5. run "rails g ember:install". Produces no output
  6. run "rails g ember:bootstrap"
  7. create controller and hit view in browser. Produces following errors in console:
    Uncaught Error: assertion failed: Ember Views require jQuery 1.7 ember.js:43
    Uncaught TypeError: Cannot call method 'extend' of undefined :3000/assets/ember-data.js?body=1:141
    Uncaught TypeError: Cannot call method 'create' of undefined ember.js:10183
    Uncaught ReferenceError: ember-rails-test is not defined :3000/assets/store.js?body=1:1
    Uncaught ReferenceError: ember-rails-test is not defined :3000/assets/controllers/application_controller.js?body=1:1
    Uncaught ReferenceError: ember-rails-test is not defined :3000/assets/views/application_view.js?body=1:1
    Uncaught TypeError: Cannot call method 'template' of undefined :3000/assets/templates/application.js?body=1:1
    Uncaught ReferenceError: ember-rails-test is not defined app_router.js:1
    Uncaught ReferenceError: ember-rails-test is not defined
  8. Run "rails g ember:bootstrap --head"
  9. Views load fine

Support compiling plain Handlebars templates?

It'd be nice if ember-rails supported precompiling plain Handlebars templates too.

I noticed the special handling with .mustache.handlebars files. I'm thinking that we could have a .plain.handlebars or .raw.handlebars extension that used Handlebars.precompile.

Ember.Map missing? -> undefined exceptions from ember-data

I'm trying to get ember-data to run with ember-rails, but I get a strange exeption when I try to instantiate the DS.Store with:

window.App.store = DS.Store.create
  revision: 3,
  adapter: DS.RESTAdapter.create({ bulkCommit: false })  

which fails on the first mention of Ember.Map:

DS.Transaction = Ember.Object.extend({
  init: function() {
   set(this, 'buckets', {
       clean:   Ember.Map.create(),

with an Uncaught TypeError: Cannot call method 'create' of undefined

As far as I could see, the Map is defined in:

https://github.com/emberjs/ember.js/blob/master/packages/ember-runtime/lib/system/map.js

so I expected it to end up in ember.js/ember-dev.js - but it is not there: How is the packaged ember.js built, what exactly should it include and not include? Should the Map be in or is there something else I need to #= require ?

PS: I just saw that the Map was added only 24 days ago - maybe it's just that ember-rails uses an older version of ember?! Then I can just fork&update, but I'd like to make sure that I'm not missing something here...

Ember views incompatible with jquery 1.8

A new rails app using the jquery-rails gem bundles jquery 1.8. jQuery 1.8 is not compatible with ember views. A tmp solution is use gem "jquery-rails", "~> 2.0.3".

Lets get ember views to play with jquery 1.8.

Rails integration instruction

If it isn't big problem, it would be great if you can fix or add step by step integration instruction. After run rails g ember:bootstrap I must search in example apps that I must manual copy ember.js file to my own project, which is very odd. For example with backbone-rails or backbone-on-rails I don't have that problems.

configuration.handlebars.templates_root doesn't work like root

A few examples of odd behavior.

The template for our experiments:

template = Ember::Handlebars::Template.new {}
Rails.configuration.handlebars.templates_root = 'app'
t.send :template_path, 'app/templates/app/example' # => "templates/example"

In previous example you can see that all instances of app directory removed, not only the root one.

Rails.configuration.handlebars.templates_root = 'app/templates'
t.send :template_path, 'app/templates/app/example' # => "app/templates/app/example"

In last example root is not removed at all.

Improve resource generation

Many of the generators are still encoding older router semantics which are now outdated. Specifically:

  1. It currently generates multiple templates for singular routes
  2. It generates view objects that are no longer necessary
  3. When using the reference type when generating a resource (e.g., rails g resource comment post:reference), the generated DS.Model should use DS.belongsTo
  4. Serializers should not generate belongs_to
  5. Generated models should extract attr, hasMany and belongsTo in a local variable at the top of the file, so that the generated code can say something like: post: belongsTo('App.Post') instead of post: DS.belongsTo('App.Post')
  6. Investigate why newly created serializers are not inheriting from ApplicationSerializer (this may have been our fault, but we should never default to inheriting from AM::Serializer)

Ember.Route undefined

Hello,

This commit : c5eb37e
switches States to Routes in the generator template, but from what I can see, Ember.Route is not defined in Ember version shipped with ember-rails.
Am I missing something ?
Are we supposed to use ember-latest.js (which defines Ember.Route) ?

ExecJS error when bundling all Ember templates together

I'm bundling all of my templates together via an all.js file that calls 'require_tree .' as outlined in the README.

This was working great until I got to 10 templates, now compilation bombs with the following error:

ExecJS::ProgramError
TypeError: Cannot read property '0' of undefined

This is nothing to do with the content of the file that eventually pushes it over the edge, it can be working fine and then made to fail by simply adding an empty template to the path.

My templates are compiled through hamlbars, but I'm not sure if that is significant in this case.

I've tried switching the JS compiler to a few different compilers (Ruby racer, nodejs) and the fail is the same, so I believe there is an error in the JS code that is generated and then passed to the compiler.

I'll attach an example of a failing file shortly, I'm not sure how to debug it further and how to narrow down to where the error is.

Thanks in advance for any help!

Problem with ember.variant in configuration files

So, I recently upgraded ember from an older version, and had to add the config.ember.variant = :production to my config/environments/production.rb

The problem is, when precompiling the assets, everything goes fine, but when I start the server, I get this error:

'method_missing': undefined method `ember' for #Rails::Application::Configuration:0x00000003e46710 (NoMethodError)

https://gist.github.com/3793642 (stack trace)

So I remove the variant line, and the app boots normally.

But with it removed, I get errors when precompiling the assets.
I am using ember-rails 0.7.0

Unable to find 0.9.1 gem

I seem to be unable to install 0.9.1 gem in my project. It always finds and installs the outdated 0.8.0 version. I am currently using it by specifying the :git option in my gemfile. Any help would be gretly appreciated.

rails g ember:bootstrap fail if don't exists application.js file

Tested in ember-rails 0.5.0 and 0.6.0

If app/assets/javascripts don't exists or not have any application.js file inside, this operation fail.

$ rails g ember:bootstrap
[EMBER-RAILS] ember.variant was not found in your current environment
insert app/assets/javascripts/application.js
/Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/actions/inject_into_file.rb:99:in binread': No such file or directory - /Users/javierav/code/ember-demo/app/assets/javascripts/application.js (Errno::ENOENT) from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/actions/inject_into_file.rb:99:inreplace!'
from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/actions/inject_into_file.rb:60:in invoke!' from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/actions.rb:95:inaction'
from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/actions/inject_into_file.rb:31:in insert_into_file' from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/ember-rails-0.6.0/lib/generators/ember/bootstrap_generator.rb:17:ininject_ember'
from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/task.rb:27:in run' from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/invocation.rb:120:ininvoke_task'
from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/invocation.rb:126:in block in invoke_all' from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/invocation.rb:126:ineach'
from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/invocation.rb:126:in map' from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/invocation.rb:126:ininvoke_all'
from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/group.rb:238:in dispatch' from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.15.2/lib/thor/base.rb:408:instart'
from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.5/lib/rails/generators.rb:171:in invoke' from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.5/lib/rails/commands/generate.rb:12:in<top (required)>'
from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:251:in require' from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:251:inblock in require'
from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:236:in load_dependency' from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.5/lib/active_support/dependencies.rb:251:inrequire'
from /Users/javierav/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.5/lib/rails/commands.rb:29:in <top (required)>' from script/rails:6:inrequire'
from script/rails:6:in `

'

config.ember shouldn't NameError when running in prod sans assets.

Currently running assets:precompile will fail without a config.ember.variant for your production environment, however config.ember will raise a NameError when starting in production when bundled without assets.

At the very least we need to document a workaround to this chicken/egg situation:

  config.ember.variant = :production if config.respond_to? :ember

However, I've been trying to think of a better way to do this. I'm happy to write the code if we can come up with a good solution. Any suggestions?

Add auto Ember.view creation to Templates?

Proposed new feature:

As a developer, I don't want to create a template, then separately define a view that uses that template.

Acceptance criteria:

The handlebars (.hb, .hjs) file handler should (in addition to creating a valid Ember template), also create a corresponding Ember view.

For example, the file "app/assets/javascript/ember/templates/post_list.hb" should create a template AND a view for the application. The view might be specified as the following:

<script type="text/javascript">

Ember.TEMPLATES[...]...

App.PostListView = Ember.View.extend({
  templateName: "ember/templates/post_list"
}); 
</script>

Any thoughts?

If I get a few +1's I'll be happy to start implementing.

Call more attention to the fact that it needs to use execjs

I'm adding ember-rails to an existing rails app. I was following the instructions but compiling kept failing. Making a request for /assets/application.js I'd get a 500 error with this message:

undefined method `enterContext' for #<Java::OrgMozillaJavascript::ContextFactory

and a reference to application.handlebars.

Eventually I realized the problem was that the rails app had this in its Gemfile:

  group :assets do
    gem "therubyrhino", "1.73.3"
  end

By removing "therubyrhino" gem (and thereby allowing execjs, which gets installed together with ember-rails), I got everything working.

Of course this issue wouldn't occur if someone were starting a new rails app from scratch. My situation is probably an edge case. Still if you want to help avoid this kind of gotcha, it might be a good idea to either include a note about the importance of allowing execjs to compile the code or, even better, perhaps perform some check during "rails g ember:bootstrap" with a warning to the user, something like "Attention, ember-rails relies on execjs but your Gemfile assigns "therubyrhino" in the assets group. Please remove that from your Gemfile and run 'bundle install'".

Server side pre-compile always escaping html content

In development mode when using the triple handlebars syntax it allows html content to be rendered correctly, i.e.

// foo.handlebars
// content = '<span style="font-weight: bold;">bold</span>'
{{{content}}}

In development renders

<span style="font-weight: bold;">bold</span>

However in production renders

&lt;span style=&quot;font-weight: bold;&quot;&gt;bold&lt;/span&gt;

Turning off server side pre-compilation in application.rb fixes the problem

config.handlebars.precompile = false

Doc or behavior issue config.ember.variant required

Hi, Looks like config.ember.variant is currently required for ember to be properly loaded.

Is this the intentional behavior and it's just missing documentation (at least I could only see it in the source) or shall it default to the Rails environment ?

Thanks for all the great work.

Latest emberjs incompatible with handlebars precompilation

When updating to the newest ember.js in an app with ember-rails, I started getting the following error:

TypeError: 'undefined' is not an object (evaluating 'Ember.$.event.fixHooks')
  (in /Users/sam/Projects/zipmark/spark/app/assets/javascripts/templates/application.handlebars)

I was able to fix this by updating the EmberRails handlebars precompiler to stub out jQuery.event.fixHooks, like so:

//// jQuery
var jQuery = window.jQuery = function() { return jQuery; };
jQuery.ready = function() { return jQuery; };
jQuery.inArray = function() { return jQuery; };
jQuery.event = { fixHooks: jQuery }; // <-- added this line
jQuery.jquery = "1.7.2";

Is this the correct fix?

Alternative file/dir layouts?

The Rails /app tree was designed for server side apps, where javascript files were small and treated merely as static assets to be served - hence /app/assets/javascript. But when using Ember, javascript is possibly your whole app.

How difficult would it be to add support to ember-rails to, for example:

  1. Store your Model.js files in /app/models alongside your Model.rb files
  2. Store your handlebar templates under /app/views, or /app/templates if you want to differentiate them from Rails views

The second example is the most important one to me. Right now my /app/views folder just contains a single home/index.html.erb file, because all of the markup is in handlebars templates stuck far away under /app/assets/javascripts/templates. It especially bugs me that a bunch of files which are essentially html are sitting in a javascript folder.

I don't know if the above ideas are good - I know this is somewhat of a new domain to most of us.

Add support for downloading ember HEAD into your project for testing

It'd be nice to be able to do something like:

rake ember:get:head

Or something, that will download the latest version of ember from github, and put it into your project. We'll also need a mechanism for not using the bundled version of ember, and one that you have in your own project. I think if you put a file in vendor/javascripts that has the same name as something in the gems, it will use that one instead. Will need to test.

Pre-Compile Inline Handlebars Templates

It's common to keep small handlebars templates inside the Javascript codebase, e.g. in views (example below). Would be nice if these would be pre-compiled in production, similar to how separate .hbs files are pre-compiled. Another benefit would be that the non-runtime part of handlebars could be skipped in production, reducing the file size.

Does this sound like a good idea? How could it be implemented?

Something similar exist in the ember-js Assetfile: https://github.com/emberjs/ember.js/blob/master/Assetfile#L23-L28

App.MyCustomSelect = Ember.View.extend({

  tagName: 'select',

  defaultTemplate: Ember.Handlebars.compile('{{#if view.prompt}}<option>{{view.prompt}}</option>{{/if}}{{#each view.content}}{{view Ember.SelectOption contentBinding="this"}}{{/each}}')

  etc: "...",

})

Automate upgrade of ember versions

I'm thinking of adding a rake task to update the js files in vendor/assets/javscripts from somewhere but don't know if there's an official ember location where the built files are posted. I'm happy to do the work and submit a pull request if someone can point me in the right direction.

I've seen 2 links on the http://emberjs.com/ site for

https://github.com/downloads/emberjs/ember.js/ember-0.9.6.min.js
https://github.com/downloads/emberjs/ember.js/ember-0.9.6.js

I can build ember and get these generated files

dist/ember-runtime.js
dist/ember-runtime.min.js
dist/ember-runtime.prod.js
dist/ember-spade.js
dist/ember.js
dist/ember.min.js
dist/ember.prod.js

BUT I am not sure how to map either of the above to the 5 files in this gem

vendor/assets/javascripts/ember-dev.js
vendor/assets/javascripts/ember-precompiler.js
vendor/assets/javascripts/ember-runtime-dev.js
vendor/assets/javascripts/ember-runtime.js
vendor/assets/javascripts/ember.js

Where has this gem gotten its .js files in the past?

Cannot use "control" multiple times if templates are rendered through handlebars files

Hi everyone,

I'm trying to render a control twice in a template (e.g. http://jsbin.com/ogorab/52/edit). I'm using master of both ember-rails and ember.js.

If I put the template code in <script> tags, it works fine. If I put it in app/assets/templates/name.handlebars files, then it fails on the second render with Cannot call method 'lookup' of undefined.

I've traced the error to line 23968 of https://gist.github.com/4699877 where container is undefined.

I've had this reproduced by others in the IRC channel.

If I can help tracking it down at all, please let me know. Thanks for all your work on Ember and Ember-rails!

Ember-rails generators dont work with rails 3.x engines

When running 'rails g ember:boostrap' from within a rails 3.x engine, it produces the following error, which has been shortened to show what i believe is the main error, an inability to recognize the rails engine folder structure:

../lib/thor/actions/inject_into_file.rb:99: in 'binread': No such file or directory -/home/dav29/rails-dev/cal/calendar/app/assets/javascripts/application.js (Error:ENOENT)

I created a branch aimed at fixing this and i am opening this issue for discussion of the best approach. This ember-rails-generators-with-engines branch have been heavily modified to allow it run with rails 3.x engine, alas the generators still fails to run;

https://github.com/mankind/ember-rails/tree/ember-rails-generators-with-engines

Please peep at the code and let's take it forward.

change description: Ember for Rails 3.1+

Since rails 3.2 is out I suggest changing the description because it takes some people (myself included) a few seconds to figure out that it's going to work just fine with rails 3.2.

Rails 3.1.5 will not boot with master

gem 'rails', '3.1.5'
gem 'ember-rails', github: 'emberjs/ember-rails'

Results in:

/Users/tpitale/.rvm/gems/ruby-1.9.2-p320@docket/bundler/gems/ember-rails-82d35eb582d4/lib/ember/rails/engine.rb:19:in block in <class:Engine>': undefined methodregister_engine' for nil:NilClass (NoMethodError)

That line is app.assets.register_engine …

Rails documentation doesn't mention app.assets anywhere I could find.

I had to remove the lines from the engine and put them in application.rb like this:

config.assets.register_engine '.handlebars', Ember::Handlebars::Template
config.assets.register_engine '.hbs', Ember::Handlebars::Template
config.assets.register_engine '.hjs', Ember::Handlebars::Template

on Rails-4.0.0.beta

∴ rails -v
Rails 4.0.0.beta

∴ bundle
Updating git://github.com/emberjs/ember-rails.git
Fetching gem metadata from https://rubygems.org/.....
Bundler could not find compatible versions for gem "railties":
In Gemfile:
ember-rails (>= 0) ruby depends on
railties (~> 3.1) ruby

rails (>= 0) ruby depends on
  railties (4.0.0.beta)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.