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
Related
Ruby is so darn mysterious when it comes to using the gems! Where do these gems reside?? In java, you can have as many jars you want just include them in your CLASSPATH and your good to go. Ruby is a simpler language, but why do I need the headache of dealing with simple crap? Can anyone seriously finally explain how the gem loading process works? It seems like no one really knows why the heck do requiring some gems work, and requiring others doesn't even if you have gem installed them and they are in the gem list. Where is the authority in ruby on this site that can finally clarify the gem loading process.
I am tried of including 'rubygems' in my ruby scripts to prevent errors like LoadError: no such file to load -- pony
And even when I do require 'rubygems' in my scripts, it still gives LoadErrors. Even if the gem is in my gem list.
When you're using Bundler to manage Gems in your project (you will have a Gemfile at the root directory of the project), be sure to run
bundle install
requiring rubygems just loads rubygems itself (and isn't required in ruby 1.9 and above)
You need to actually load each gem individually via require.
If you use bundler, then you can optionally have bundle auto require everything from your Gemfile
I'm trying to create a rails engine that will use javascript from a gem dependency that I have added to the engine. However I keep getting "couldn't find file 'fullcalendar'" when I put the following line in my application.js for my engine:
//= require fullcalendar
This line is loading the javascript from the gem dependency into the rails engine.
This same line will work when the gem is installed on a normal rails app (not engine). What am I missing here? Can an engine load javascript from another engine/gem?
UPDATE:
Researching on my own the issue could be that sprockets only looks for javascript inside the engine. The gem dependency is installed into vendor/cache of the parent app NOT the engine therefore //require fullcalendar fails because it is looking within the engine and the javascript for fullcalendar is in the parent application.
What confuses me is that if I include fullcalendar in the parent application gemfile explicitly than I am able to access it in the engine. This doesn't make sense to me. In both instances the full calendar gems javascript is in the parent app, but the behavior is different. Including the gem in two places is unappelaing to me and doesn't seem like a proper solution. Any thoughts?
I had some trouble with this in the past.
App > Engine 1 > Engine 2
Engine 1 and Engine 2 worked fine on the app. I created a dummy app in Engine 1 to test Engine 2's functionality, also worked fine. But when I put Engine 1 in App it didn't work at all.
My big mistake here was only including Engine 1 in App, Engine 2 has to be included as well!
Inheritance does not work for Gemfiles, just dependencies.
A little late to the party, but I recently had the same issue. Here is my post to describe it the solution http://grantrklinsing.com/articles/2013/01/10/adding-3rd-party-assets-to-a-rails-gem.html. Hope it helps if you didn't get it working.
Does the fullcanendar gem you're using come with an installer? Some gems come with installers for model migrations, assets, views, config files, etc.
If you're referring to the fullcalendar-rails gem it comes with an installer that you have to run using the
rails g fullcalendar:install command.
If the gem doesn't come with an installer you can manaully clone the gem to your local machine by running git clone gem_github_repository_url_here.git which will enable you to navigate the gem's folders and you'll have direct access to any of the assets that the gem uses which can be copied over to your rails application.
If your Engine has a dependency added through the gemspec file, you need to require this dependency directly before Engine initialization.
app/lib/app/engine.rb
require 'fullcalendar-rails'
module App
class Engine < ::Rails::Engine
isolate_namespace App
end
end
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.
I've been trying to use HTTParty in my rails code
sudo gem install httparty
From the command line I can now successfully do
httparty "http://twitter.com/statuses/public_timeline.json"
When I try this in my rails app
require 'rubygems'
require 'httparty'
class FooController < ApplicationController
include HTTParty
def bar
blah = HTTParty.get("http://twitter.com/statuses/public_timeline.json")
end
end
I get the error message "no such file to load -- httparty"
I suspect there is something wrong with my environment?
You don't need to do 'include HTTParty' inside the Controller. Just remove that and it should work. I just tested it and it worked for me. If this doesn't work for you, you should add the gem to your environment.
Usually if you use a gem inside your Rails application, you should add the following to environment.rb:
config.gem "httparty"
The gem will be available in the application now and you don't need to add 'require' inside the Controller. Also, you don't need to require RubyGems inside a Controller.
When you use Rails 3, you need to put the following inside the Gemfile:
gem "httparty"
I hope it works for you. :)
The problem is, if you load a new gem, you have to restart the server even if you are in development.
I had this same error. I tried moving the require HTTParty all over, but found, all I needed to do was restart the rails server In the end I did not need to 'require HTTParty' nor 'include' it. It just needed to be loaded into rails.
1)include the httpary in your gemfile
open your gem file then add
gem 'httparty','YOUR VERSION NUMBER'
2) run bundle install in your command prompt of the app file
3) restart the server
Ran into the same problem. Then I switched from Ruby 1.8.7 to Ruby 1.9.2 and all errors varnished into thin air.
(Yes, it first took me quite some hours to come up with the possibility that the Ruby version might be the problem. Configured a secundairy server to avoid possible conflicts with 2 ruby versions, and after way to many hours I got my RoR stack up and running. And the first test with httparty (based on the example on top) worked out of the box! Finally can sleep RESTfully again :-)
I run into the same error whilst reviewing a project from a student, I change the name of the Gem from uppercase to lowercase then run bundle install. I then went ahead to change the format in which they were being imported from
require 'HTTParty' to require 'httparty' and boom it worked
When creating a new Rails project using:
rails sample
Then creating a model using:
script/generate model person first_name:string last_name:string
Everything is fine. However, if I add any gems to my environment.rb:
config.gem "authlogic"
And run the same generator, I get the following:
/Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning:
Gem::Dependency#version_requirements
is deprecated and will be removed on
or after August 2010.
The warning just recently appeared (I think), but I would like to fix it if possible. Any hints or similar experiences?
Thanks.
did you try:
rake gems:install
Btw. If you are using rubygems 1.3.6 then you get this deprecation warning. Previous versions never gave a warning. Also i suggest installing any gem using the command line rather than adding it in the environment.rb file. If the gem(s) you have added in the file is/are not installed, then the generator or any rake task will simply not run. Its a minor bug.
Here is an article that describes a way to prevent the warning:
http://www.mattvsworld.com/blog/2010/03/version_requirements-deprecated-warning-in-rails/
Its no big deal though. Just install gems the normal way and don't add any to your environment.rb file. You'll never get the deprecation warning.
This may be irrelevant as it is rails 3.0 but the answer you are looking for is in this article:
http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade
down by the section titled "config.gem is dead, long live bundler", although the article does explain some new things.
You may want to consider upgrading to rails 3.0 and when you do, you will be using the Gemfile inside your application. in here, you will want to include the line:
gem 'authlogic'
and then on the command line, run
sudo bundle install
After that, all should be set :)
Check https://gist.github.com/807008 they suggest to downgrade and upgrade again rubygems.
Worked for me...
Putting these lines in your config/environment.rb between your bootstrap and your initializer will remove the deprecation warning:
if Gem::VERSION >= "1.3.6"
module Rails
class GemDependency
def requirement
super == Gem::Requirement.default ? nil : super
end
end
end
end