Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: JST is not defined #59

Open
svishniakov opened this issue Aug 1, 2017 · 3 comments
Open

Uncaught ReferenceError: JST is not defined #59

svishniakov opened this issue Aug 1, 2017 · 3 comments

Comments

@svishniakov
Copy link

I've caught JST is not defined error in a browser console after new project creation. Just wanted to have some experiments with skim.

Gemfile

gem 'rails', '~> 5.1.2'
gem 'sqlite3'
gem 'puma', '~> 3.7'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'slim-rails'
gem 'jquery-rails'
gem 'slim-rails'
gem 'skim'
gem 'therubyracer'

application.js

//= require jquery
//= require jquery_ujs
//= require rails-ujs
//= require turbolinks
//= require skim
//= require_tree .

books.coffee file

skim = ->
  $("#greeting").html JST["books"]({world: "World"})

$(document).ready(skim)

books.jst.skim in the same location where books.coffee files located
p Hello #{@world}!

I would appreciate any advise on how to solve the issue and add skim to my application correctly?

Regards,
Sergey

@svicalifornia
Copy link
Collaborator

svicalifornia commented Aug 3, 2017

Hi Sergey,

Thanks for writing in and for using Skim.

Just to cover the basics, did you name your Skim file with a .jst.skim extension? Skim uses Sprockets to require the files and convert them into JavaScript, and Sprockets will only define the JST object if your file includes .jst in the extension.

@svishniakov
Copy link
Author

Hi Shawn,

Yes, everything according to README. For now, I've solved the issue and there are the steps:

  1. Put *.coffee file in app/assets/javascripts folder
  2. Related *.jst.skim file needs to be placed in the same folder
  3. Adjust application.js manifest file and register your *.jst.skim template there together with skim itself, like:
//= require skim
//= require <your_jst_skimfile>
  1. Run server rails s and everything should work
  2. //= require <your_jst_skim> file could be removed from application.js after

Regards,
Sergey

@p0m1d0rka
Copy link

p0m1d0rka commented Aug 31, 2017

Hi.
I think the better solution is

  1. put all jst templates to assets/javascripts/templates folder
  2. in application.js require in this order
//= require skim
//= require_tree ./templates
//= require_tree .
  1. in your coffee files call templates like JST['template/file']

all because require_tree . can includes coffee files before jst template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants