I'm just trying to build an app on rails to do a simple search on flickr. Unfortunately, before I can do anything remotely interesting, it doesn't seem to recognise the 'flickr' gem I installed. As a simple test, all I did was to generate a controller called flickr with a method called flickrsearch. In that method, all I put in there is
require 'flickr'
but in the browser, I have the following error:
cannot load such file -- flickr
In fact, I originally wanted to require 'flickr' in config/environment.rb but the server wouldn't even fire up. It gave me errors saying it couldn't load flickr. I've tried it with other installed gems as well but same result.
A month ago when I first played around with Ruby, I installed Ruby and some gems as well. Everything worked fine...but recently, I installed Rails using Railsinstaller on http://railsinstaller.org/ (I use Windows 7). So I'm guessing it's looking in the wrong place for gems.
So it looks like I originally had gems in c:\Ruby193 and now I also have gems in c:\RailsInstaller\Ruby1.9.3
So...I decided to delete the whole c:\Ruby193 in a moment of madness...I know, probably not the cleanest way to do it.
Then reinstalled the flickr gem (gem install flickr). This time, it actually create the gem files for flickr in c:\RailsInstaller\Ruby1.9.3. Which is what I expected but I'm still having the problem of Rails not recognising the flickr gem.
Please help...Many thanks.
Sam
You should not have to explicitly require gems in Rails. Just make sure you've added the flickr gem to your Gemfile and you've run the bundle install command.
Related
I have an app which is using a new gem I've been making (first attempt ever to make a gem) and it doesn't matter what I do I can't update the gem in my rails app. I've built the gem, then installed it (e.g. gem install ./youtube_query-1-0-6.gem). When I view it in irb it works as expected. I then proceed to register it with rubygems, this works successfully (again, it seems). So, when I add it to my Gemfile in my rails app and hit bundle install (or bundle update then bundle install if I've change the version) I can see it has installed the latest version. But, when I view my rails app page that uses the gem and debug the data that is returned it doesn't change and is inconsistent with what I'm seeing in irb.
Next, I try to just return something completely different so I know that it has updated - return "hi". When I follow the steps above so I can see "hi" being returned in irb, then proceed until bundle update/ bundle install (confirming that the "hi" version is shown) then debug what the gem returns - still, no change in my app.
Finally, I do bundle uninstall youtube_query and tell it to delete all versions. This seems to work. But still my page returns old data - even though I've apparently uninstalled it. I've even tried removing it from the Gemfile then bundle install and STILL it works.
OK, my understanding is obviously wrong of how this may work. Is there anything I should know about gems that clearly I don't? How can I most importantly update properly the gem in rubygems and my Rails app. Thanks.
http://rubygems.org/gems/youtube_query (my gem)
I am developing a Rails app that uses a gem that I am also developing.
Every change that I make in the gem I have to: build, uninstall previously installed gem, install built gem, restart rails app.
You can imagine that it easily becomes a nightmare to make even litle changes in the gem.
I´ve tried to manually load all files that are configured to be loaded by the gem (at Gemspec) but it always seem to be some problem in the loading process, not finding libraries or not loading in the proper order.
Is there a way to set my environment to better develop my gem with my app?
You can just add a file reference to your local filesystem in your Gemfile, like
gem 'new_gem', :path => '~/RubyPlayground/DevGems/new_gem/'
That way you just need a new bundle install after modifying your new gem.
Update
Reading your description again you might not be using rails 32. My suggestion is of course based on bundler at least.
You could always symlink your gem code to lib/ and then include that in your autoreload paths (application.rb IIRC).
I have a RoR server that I am decommissioning and need to move the existing Rails apps to a new server. The Rails apps are running Rails 2.3.5 and RubyGems 2.3.5.
The problem I am having is that some of the Gems do not seem to be available anymore - one example is thoughtbot-paperclip --version=2.3.1
I need to install these gems in order for the apps to work on the new server.
Would these gems have been removed from the remote repos? And if so how can I transfer them to the new server? I have tried just copying the entire gems folder from one server to the other but this does not seem to work.
Most of the old gems got renamed, as they usually were in a github_username-gem_name format. But after GitHub stopped hosting gems and gemcutter.org came, they got renamed to only the gem_name, such as thoughtbot-paperclip to just paperclip.
You might get away with just specifying the version number in a Gemfile, such as
gem 'paperclip', '2.3.1'
Looks like the gem has been renamed to simply paperclip. Check the repository.
I'm trying to run this method which should work according to this:
ActiveSupport::TimeZone.new("whatever",3600)
but this initializer doesn't exist.
So I would like to look at the sources for my Rails version (2.3.4) to see if it's private or if I'm missing the point completely (the one-argument constructor works).
And suddenly I realize that I have no idea where to find the docs for my version nor the API. I use api.rubyonrails.org constantly (linked from here), but I'm not even sure what version it refers to (2.3.2, the 'current' version?). How can I get the API docs for my installation? How can I view the SOURCE for my Rails version? Can I view it in my Rails installation (either OSX or Ubuntu)? Online?
If the version were vendored (it's not), how would that affect my question?
Check out http://github.com/makandra/aegis/tree/master for a local gem documentation server. Even simpler is the gem server command. Both give documentation for installed versions of gems.
Also, sometimes gem install skips generating RDoc documentation; use gem rdoc --all to create docs for all installed gems. The docs are saved to /your-ruby-path/lib/ruby/gems/1.8/docs, by the way.
The source for all gems is at /your-ruby-path/lib/ruby/gems/1.8/gems, that includes both Rails and ActiveSupport, which are actually two separate gems.
There are several ways to get at your docs, the easiest being with a frozen rails gem. If you don't want to freeze it for some reason you can create a dummy rails app, freeze rails, and gen the docs:
rails dummy_app
rake rails:freeze:gems
rake doc:rails
rake rails:unfreeze
You can also generate docs for plugins you have installed. Try rake -T doc.
Freezing your rails gem has the added benefit that the code is right there for you to browse, but you can always go to wherever your gems get installed on your system. On MacOS this could be either ~/.gems, /Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems, or maybe other?
I'm trying to get tags working in my rails application and want to use acts_as_taggable. Firstly I followed the instructions I found in Rails Recipies (a free sample bit online) that used the acts_as_taggable plugin. However, I then found this site which seems to have a gem for acts_as_taggable which is more advanced (has options for related tags etc).
I've tried to follow the instructions there to install it, but I keep getting errors.
Firstly I installed the gem as normal (gem install acts_as_taggable) and then I tried various ways to get rails to recognise and load the gem. The require_gem listed on the site didn't work (I assume that is an old command that has been removed) and neither did a straight require (although that has worked for my bluecloth gem).
I've then tried using config.gem 'acts_as_taggable' but that keeps telling me that I haven't got acts_as_taggable installed and asks me to run rake gems:install. No matter how many times I run that it still gives the error!
The result of the gem query -l -n acts_as_taggable lists acts_as_taggable as an installed local gem.
I've tried running gem check and that doesn't show any problems.
The response I get when I try to require it from the console is:
MissingSourceFile: no such file to load -- acts_as_taggable
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `ge
m_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `re
quire'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_suppo
rt/dependencies.rb:510:in `require'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_suppo
rt/dependencies.rb:355:in `new_constants_in'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_suppo
rt/dependencies.rb:510:in `require'
from (irb):1
It looks like for some reason it can't find it. Any ideas why?
You could also try acts_as_taggable_on_steroids:
This plugin is based on acts_as_taggable by DHH but includes extras such as tests, smarter tag assignment, and tag cloud calculations.
I've used it recently. Aside from some performance issues, it works very well and, unlike taggable, is under active maintenance.
Have you tried running something like "gem query -l -n taggable" to check whether it has installed correctly into your local gem repository?
If it has you could use some of the built in checks against it - Gem is good for this - to make sure it installed as it is supposed to.
That would be my first avenue to explore.