I'm trying to use the pdf-reader gem
(https://github.com/yob/pdf-reader) on my app (RoR with Mongoid).
Unfortunately it doesn't work. I've put the gem in the Gemfile (and have done 'bundle install'). Here's my feedback:
uninitialized constant ActionView::CompiledTemplates::PDF
view-file
<% PDF::Reader.new("somefile.pdf")%>
I've tried to include the library in the model, but it doesn't work.
class User
include Mongoid::Document
include ::PDF::Reader
I get this error
uninitialized constant PDF
Do you know how to use the pdf-reader library on Mongoid?
I am looking forward to your answers. THX!
You need restart the server. After all gem add on your Gemfile, you need restart server to have this gem require in your application.
Related
I want to use the Google API in my Rails application. For this, I need to authenticate to a Google Dev account to get the authentication_token.
The best way to do it, in my opinion, is to use oauth2 library and examples provided in the documentation.
As you see, I have tried to use Google::APIClient in there, although I am stuck with the following issue below
In the console I get:
Google::APIClient::KeyUtils.load_from_pkcs12('file.p12', 'notasecret')
NameError: uninitialized constant Google
I'm using following gems:
gem 'oauth2'
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'google-api-client'
Any suggestions?
You just need to require a file
require 'google/api_client/auth/key_utils'
Only then you would be allowed calling a Google::APIClient::KeyUtils.
You can notice in the documentation they require each class/module separately.
It seems like gem does not load all of its dependencies itself, because of their ideology and just not to overload the application with redundant libraries that won't be used.
Take a note, it is quite possible you will need to require some other libraries.
ok I'm using sorcery gem for the log in of the main engine.
And I want to use it also in the main engine but whenever I call the user model in the
mountable engine it says
undefined method `authenticates_with_sorcery!' for User:Class
When I said call it's like
#user = User.new
By the way I'm using mongoid 4.0.0 and rails 4.1
I ran into similar issues using MongoMapper. Try making sure that authenticates_with_sorcery! appears beneath any of your database-related includes. For example:
class User
include Mongoid::Document
authenticates_with_sorcery!
end
In my case, the gems order in the gemfile was apparently wrong
Not good
gem 'sorcery'
gem 'mongoid'
Works!
gem 'mongoid'
gem 'sorcery'
As far as I remember when I posted this question sorcery gem doesn't support Mongoid 4 yet so they make a new branch in the github so that for those who are using Mongoid in that time can use sorcery with mongoid 4. Well basically the solution works for me is that I need to reference that branch in my Gemfile. I don't know right now if they already publish the latest sorcery gem.
I had some issues with a different ODM yesterday so I decided to take a look at Mongoid instead. The wiki tutorial was pretty thorough, so it seemed like it was worth a shot. I went through the wiki article very carefully but may have missed something. Perhaps this is happening because I had a different ODM in the app yesterday. Anyway, now I'm getting an error:
uninitialized constant User::Mongoid
with this line of code (threw this in to confirm it was this method that was the issue):
<% if user_signed_in? -%>
5: Hello user
6: <% end -%>
user_signed_in is a Devise method. I suspect that Devise isn't actually loading but I'm not sure what to do next.
My gem file has gem "devise", "1.5.0" and I've run a bundler install, I can see that devise is getting installed. I've confirmed that my application controller exactly matches the app controller in the sample. My app starts with no issues when I run rails server. All the models in the app load correctly when I do load 'app/models/user.rb'. The file config/initializers/devise.rb has require 'devise/orm/mongoid'. I've verified that my User model exactly matches the one in the tutorial.
What should I look at next?
Update: This was fixed, but I'm still missing how. I started the app on a new port. That's all it took. I was making changes to my index.html.erb and seeing those changes in the error that I was getting so I know the new code was being seen. But when I started the app on a new port the error went away. Perhaps there's some sort of 'hard recompile' in rails that I'm not aware of?
First, confirm that the error is still happening after you fully restart your rails instance.
I suppose that in the User model you have something like this:
class User
include Mongoid::Document
devise :database_authenticatable, ...
end
Check in config/initializers/devise.rb:
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/mongoid'
Also check that devise gem is under mongoid gem in Gemfile:
gem "mongoid", "~> 2.3.2"
gem "bson_ext"
gem "devise", "~> 1.4.9"
This is going to be a really dumb question, I just know it, but I'm going to ask anyways because it's driving me crazy.
How do I get acts-as-taggable-on to work?
I installed it as a gem with gem install acts-as-taggable-on because I can't ever seem to get installing plugins to work, but that's a whole other batch of questions that are all probably really dumb. Anyways, no problems there, it installed correctly.
I did ruby script/generate acts_as_taggable_on_migration and rake db:migrate, again no problems.
I added acts_as_taggable to the model I want to use tags with, started up the server and then loaded the index for the model just to see if what I've got so far is working and got the following error: undefined local variable or method `acts_as_taggable' for #.
I figure that just means I need to do something like require 'acts-as-taggable-on' to my model's file because that's typically what's necessary for gems. So I did that hit refresh and got uninitialized constant ActiveRecord::VERSION. I'm not even going to pretend to begin to know what that means went wrong.
Did I go wrong somewhere or there something else I need to do. The installation instructions seem to me like they just assume you generally know what you're doing and don't even begin to explain what to do when things go wrong.
Did you try to define your gem dependencies in config/environment.rb (Rails 2.3):
Rails::Initializer.run do |config|
#...
config.gem 'acts-as-taggable-on'
#...
end
Or in Gemfile for Rails 3 or if you use already Bundler with rails 2.3:
gem 'acts-as-taggable-on'
This should make the require 'acts-as-taggable-on' unnecessary
Maybe following the installation here can help.
For example you don't need to:
require 'acts-as-taggable-on'
but:
class User < ActiveRecord::Base
acts_as_taggable
end
Otherwise you need to post more details about the error.
I installed acts-as-taggable-on for my app through github. If you want to try that method instead of the gem, you can read my this post that explains my experience: http://blog.mediummassage.com/2010/04/27/creating-categories-in-the-store-with-tags/
I've followed the instructions here, installing the composite_primary_keys gem via
sudo gem install composite_primary_keys
That worked fine. Now when I add the following to my model
set_primary_keys :user_id, :group_id
and I get
undefined method `set_primary_keys' for #<Class:0x1043bfe20>
Also, using multiple primary keys in a migration as described here has no effect.
Any ideas why this might not be working and how to make it work?
Note: I do not want a speech on why I should not be using composite keys--I have already made up my mind and just want to get this working. Thanks!
Did you add require 'composite_primary_keys' to the bottom of your environment.rb file as described here?