RoR 5.1.4 Sprockets es6.erb - ruby-on-rails

Have a Ruby on Rails 5.1.4 project with a single model. The application does not compile my app/assets/javascripts/posts.es6.erb file.
The idea is to pass a Ruby value to a ES6 Javascript bridging it with ERB like so: console.log('<%= Rails.env %>').
When changing my file to app/assets/javascripts/posts.js.erb it works fine but the es6 extension fails.
Rails just seems to silently ignore my es6.erb file.
Can anyone help?

Related

Configuring Rails to generate the correct first line in development.rb

I am using Rails 4.1.1 and Ruby 2.0.0. When I run rails new test_app, the generated file test_app/config/environments/development.rb always contains the first line:
Rails.application.configure do
The above line causes an undefined local variable error. It should be:
TestApp::Application.configure do
Is there a way to configure rails so that it always generates the correct name?
Using Ruby 2.0.0 and Rails 4.1.1, I just created a new Rails app using the command rails new test_app_rails_4-1-1. The top line of the development.rb file is Rails.application.configure do, which is the correct syntax.
I just looked at a the development.rb file in a Rails 4.0.1 app. The first line in that file is HeyLookARailsApp::Application.configure do. So it seems like the syntax in Rails 4.1.1 is different that Rails 4.0.1.

Twitter bootstrap and rails

Im trying to put the bootstrap source files in my rails project but I am not seeing an "assets" folder in my app folder. Are the Image, Javascript, and CSS folders in "public" the same thing? If not then where do I put the source files? I am using ruby version 1.9.2-p290, rails version 3.0.19, and bootstrap version 2.3.2. Not sure if that makes a difference or not.
Why don't you just use a bootstrap gem like bootstrap-sass instead?
Look at this project: twitter-bootstrap-rails
It is an easy way to set up bootstrap in your Ruby on Rails project.

Using Sass in rails 3.0.1

i am trying to use sass in a rails 3.0.1 project that i am working on. I install the gem but when i create a scss file and add some style nothing happens. I've been searching for an answer and it seems others have haml installed as well, do I need this?
I think you should add the assets pipeline (Sprockets) in addition to SASS.
Here is a gist that explains the setup for Rails 3.0.x.
https://gist.github.com/911003

JRuby with YAML

When I use Rails with YAML I change boot.rb with
require "yaml"
YAML::ENGINE.yamler = "syck"
It works fine with normal Ruby.
When I transfer the application from Ruby to JRuby, it doesn't work.
Where should I write these lines in JRuby?
Syck is a native gem. a gem that builds native extensions that is. jRuby and native extensions do not mix. Just don't use that syck snippet and your jRuby problem should go away.

uninitialized constant on class from ruby gem

I am trying to implement a gem called stanfordparser which can be found here: http://stanfordparser.rubyforge.org/
It is a ruby wrapper for a java natural language parser
I am developing in netbeans using ruby on rails / jruby on a windows 7 machine. My web app works fine otherwise, but when I try to add the parser wrapper it breaks.
Here is the code that is causing a problem:
gem 'stanfordparser'
def show
parser = StanfordParser::LexicalizedParser.new
#words = parser.apply("This is a sentence.")
end
this is in the taskscontroller
and when I go to tasks/show (which, if i remove this code, works fine) I get the following error
uninitialized constant TasksController::StanfordParser
I have made sure the gem is installed in netbeans
I am very new to ruby on rails, and teaching myself, so it may be something obvious
Thanks!
EDIT: I checked my glassfish server logs and it says
SEVERE: Missing these required gems:
stanfordparser
which is weird because I've installed the gem using netbeans, I've done rake gems:install and netbeans says the gem is installed. I've checked in netbeans gems folder and the gem is installed there.
EDIT 2:
So, after a lot of research and head banging, I've decided to simplify things a bit by just trying to use jruby to implement the java classes, now I need to figure out how to import the stanfordparser java classes (there are at least 50), I think I need to compress all the classes into a jar so that jruby can load it. maybe.
If you are using Rails 3 then the gem 'stanfordparser' statement needs to be specified in Bundler's Gemfile within the project's root. Otherwise, for Rails 2.x you need a config.gem 'stanfordparser' statement within config/environment.rb.
I was able to solve my problem the following way:
instead of using the stanfordparser ruby wrapper (which implements java ruby bridge to connect the java stanford parser to pure ruby), I use jruby to just implement the java from the stanford parser.
the code that ended up working:
include Java
require 'C:\\Stanford-Parser\\Current\\stanford-parser.jar'
require 'rubygems'
include_class 'edu.stanford.nlp.parser.lexparser.LexicalizedParser'
lp = LexicalizedParser.new(args) #args is the arguments, not copied here

Resources