dart-rails
dart-rails copied to clipboard
File Not Found Error
Adding the following line to the application.js file resulted in a file not found error. //= require dart_app
I was able to get it to work by following the instructions for using both dart and js.
It was not initally apparent where one should put code. At first, I thought it was just like coffee script. It wasn't until I looked at your sample code that I saw that it goes in dart_app.dart and more importantly in dart_app.js.dart2js. You might consider adding this to your read me file. I would do a pull on it, but I came across another update waiting. It may already address the problem.
I'm not entirely sure what went wrong on your side but i may have to add the following:
If you choose the //require= dart_app way, make sure your dart_app does not run code that requires that the page is already loaded or put the <%= javascript_include_tag 'application' %> at the bottom of your layouts body. The dart+js way allows for applications not waiting for the page to be loaded because the scripts get included at bottom of the body anyways.
Do NOT put the code in the dart_app.js.dart2js that file should conatin only one line: //= include dart_app.dart OR be a symlink to dart_app.dart (depending on your sprockets version) and this is mentioned in the README. Dart-code goes in the assets/dart/dart_app.dart
Try reverting your app/assets/dart/dart_app.js-dart2js to a symlink (easiest way would be to rerun rails g dart:assets and overwrite the file, just make sure your code is safe), make your layout look something like this:
<!DOCTYPE html>
<html>
<head>
<title>DartRailsSample</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
<%= javascript_include_tag 'application' %>
</body>
</html>
and don't forget to clean the tmp/ directory. Call back if it still doesn't work.
PS:
If you encounter an error like this:
...js_compat_engine.rb:11:inblock in class:JsCompatEngine': undefined method append_path' for nil:NilClass (NoMethodError)
i'm already on it, discovered it just now.
9c12f7ab3a878cb3bd4e8cc48581891dfb65a678 mainly addresses mentioned issues
try HEAD gem 'dart-rails', git: 'https://github.com/m0gg/dart-rails.git' if you like
I'm having problems with the //include in dart_app.js.dart2js. It's not being processed so I copy and paste from dart_app.dart when I make a change. I thought the include worked at one time. I've had been trying to get it the code to work with turbo-links without sucess so I commented it out. I was about to start researching how the files are scanned for directives. I wasn't sure if it's stricly a Rails process or is done by my IDE: RubyMine. I like your symlink solution.
My script calls are currently in the the head and they seem to work. I may move them to the bottom just to be safe.
RubyMine is a damn fine choice as IDE, i'm using it as well. You should symlink your dart_app.js.dart2js as it's backwards compatible. If you want to use Turbolinks, you should put the <script> tags for your dart-code in the <body>, this will make it work.
You can try to omit the //= require dart_app in your application.js and just put this at the bottom of the layouts <body>:
...
<%= javascript_include_tag 'dart_app' %>
</body>
...
This will cause the dart application (compiled to js) to rerun when Tubolinks loads changes and will prevent the other javascripts from beeing rerun too.