Incompatability between Rails 2.3.5 and Omniauth - ruby-on-rails

I use Rails 2.3.5 and want to use Omniauth however I can't get them to work together, as rails 2.3.5 requies Rack 1.0.1 and Omniauth (version 0.1.6) requires Rack 1.1
I deploy on Heroku so I don't believe I can hack into Rails and remove the hard dependency on version 1.0.1 of Rack.
Any help very much appreciated.
Paul

We had a similar issue. We were on Rails 2.3.4 and wanted to use OmniAuth (0.2.6). Unfortunately the only possible solution I've found so far is to upgrade to Rails 2.3.8 or later which runs on Rack 1.1 (the minimum required by OmniAuth) and then require OmniAuth like so:
# In config/environment.rb require 'omniauth' (or 'oa-<strategy_name>') before Rails::Initialize
require 'omniauth'
Rails::Initializer.run do |config|
...
# Add your own initializer for OmniAuth
# /config/initializers/omniauth.rb
ActionController::Dispatcher.middleware.use OmniAuth::Builder do
# your strategy provider logic
end
This was mostly groomed from this thread / links in it: http://groups.google.com/group/omniauth/browse_thread/thread/676fa835428e9c83
Unfortunately I'm in the middle of all of this right now so I can't promise this works fully as I'm using a custom strategy and haven't quite made it all the way to the end yet. Hopefully it provides some starting points for you to dig deeper if you're still stuck on this if nothing else.

Related

Using rack-proxy with Rails to access Faye

I have a rails app which provides real-time functionality through Faye. My clients are going to access the Faye server through example.com:9292/faye. Instead of using that address and revealing my machine's open ports, I am trying to add a rack middleware and by using 'rack-proxy' gem, proxy my example.com/faye requests to example.com:9292/faye. My Rails middleware code looks like this:
class FayeProxy < Rack::Proxy
def rewrite_env(env)
request = Rack::Request.new(env)
if request.path =~ %r{^/faye}
env["HTTP_HOST"] = "localhost:9292"
end
env
end
end
Also I added the middleware to config/application.rb by config.middleware.use "FayeProxy", but when I run my rails server I get the following error:
/gems/ruby-1.9.3-p194/gems/rack-proxy-0.5.0/lib/rack/proxy.rb:12:in 'initialize': undefined method `key?' for # (NoMethodError)
and even if I remove meta_request gem I will get
*/gems/ruby-1.9.3-p194/gems/rack-proxy-0.5.1/lib/rack/proxy.rb:12:in initialize': undefined methodkey?' for # (NoMethodError)
*
Any help is really appreciated if anybody has experienced this before or knows the solution.
P.s. I'm using Rails 3.2.13, rack 1.4.5, rack-proxy 0.5.1.
It seems that the rack proxy shall not be treated as middleware, rather it should be mounted via routes as described here: http://inductor.induktiv.at/blog/2010/05/23/mount-rack-apps-in-rails-3/.
I know this is old, but I was just having a similar issue, but I suspect that the folder you faye_proxy.rb is in is not included in rails by default.
Adding an initializer maybe ./config/initializers/proxy.rb which contains
require "#{Rails.root}/lib/faye_proxy.rb"
Replace lib with wherever you put the proxy.

How to solve a ruby on rails version discrepancy (backward/forward compatability)

I'm new to Ruby/Ruby on Rails and I'm working with project fedena which runs on Rails 2.3.5. I looked around for a rails schema visualizer.. but I found that there are only some gems that support rails 1.x and others that support rails 3.x.
Is it possible to get a RoR application that was built with a certain RoR version in mind and compile it again for another version of RoR? I've been researching about backward/forward compatibility in Ruby and I'm getting un-encouraging results. It seems there are significant difference across the various RoR releases.
I saw your problem i had it too but i used this:
GO TO /project/config/environment
and add this code
Rails::Initializer.run do |config|
config.time_zone = 'UTC'
config.gem 'GEM_NAME', :version => '~> 2.3.5'
end
THIS WILL HELP YOU WITH YOUR TESTING

Rails sitemap_generator Uninitialized Constant?

I'm trying to use the Rails site map_generator gem to generate site maps for a 8,000,00 page site. The gem can be found here: https://github.com/kjvarga/sitemap_generator
Here is my code in sitemap.rb:
require 'rubygems'
require 'sitemap_generator'
# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "http://www.mysite.com"
SitemapGenerator::Sitemap.create do
add '/content.aspx?page=privacypolicy'
Product.find_each do |product|
add product_path(ppid), :lastmod => content.updated_at
end
end
However, when I run
>> ruby sitemap.rb
I get an error that says:
sitemap.rb:9:in `block in ': uninitialized constant
SitemapGenerator::Interpreter::Product (NameError)
However "Product" is the correct name of my model. Why is this happening?
I'm running Rails 3.1.2 and Ruby 1.9.
I'm the author of the gem. Better to open an issue on the GitHub page in future. SitemapGenerator does work in Rails 3 and Ruby 1.9.*. If you are running Rails, you don't need these lines:
require 'rubygems'
require 'sitemap_generator'
Also you generate your sitemaps by running Rake:
rake sitemap:refresh:no_ping
What is happening in your case is that because you're not running through Rake, the script does not know about the Product class, since your Rails environment hasn't been loaded.
Well, I wasn't able to get this gem working. My guess is that it doesn't work on Rails 3.1.2 or with Ruby 1.9. However, I was able to get another gem (big_sitemap) to work. Here is the link to it.
https://github.com/alexrabarts/big_sitemap

Ruby on Rails, LinkedIn:Module error

Has any one come across this error?
NoMethodError (undefined method `new' for LinkedIn:Module)
I think it's related to omniauth and linkedin. Here's my Gemfile:
gem 'omniauth'
gem 'linkedin', :git => "git://github.com/redbeard-tech/linkedin.git", :branch => 'jsapi'
I'm using:
ruby 1.8.7 (2010-01-10 patchlevel 249)
rails 3.0.5
What might be the reason for it?
Check what version of omniauth you are using. We recently ran into this and it was from our dev environment having omniauth 0.3.x and the new environment getting the new 1.0 release. On the omniauth github site it says:
OmniAuth 1.0 has several breaking changes from version 0.x. You can set the dependency to ~> 0.3.2 if you do not wish to make the more difficult upgrade. See the wiki for more information.
I suspect you're being bitten by that.
From the error message it looks like you are calling LinkedIn.new(...), but looking at the documentation it seems like it should be LinkedIn::Client.new('your_consumer_key', 'your_consumer_secret'). LinkedIn is a module, not a class and therefore doesn't have a new method. However, there seems to be class called Client defined within this module, which you have to instantiate.

Couldn't find 'devise_install' generator - Rails 2.3.8, Devise 1.0.8

I'm trying to get Devise up and running with a freshly generated Rails
2.3.8 app.
This is the error I'm running into:
devise > script/generate devise_install
Couldn't find 'devise_install' generator
I do have the Devise and Warden gems specified in my config file:
config.gem 'warden', :version => '0.10.7'
config.gem 'devise', :version => '1.0.8'
The gems are installed:
devise > rake gems
- [I] warden = 0.10.7
- [R] rack >= 1.0.0
- [I] devise = 1.0.8
- [I] warden ~> 0.10.3
- [R] rack >= 1.0.0
I = Installed
F = Frozen
R = Framework (loaded before rails starts)
Looking at the list of generators, I don't see anything from Devise:
devise > script/generate
Installed Generators
Rubygems: cucumber, facebook, facebook_controller,
facebook_publisher, facebook_scaffold, feature, integration_spec,
publisher, rspec, rspec_controller, rspec_model, rspec_scaffold,
session, xd_receiver
Builtin: controller, helper, integration_test, mailer, metal,
migration, model, observer, performance_test, plugin, resource,
scaffold, session_migration
Any clues?
in 1.1.5 its
rails generate devise:install. I have seen devise_install in some tutorials.
I ran into the same problem myself and, unfortunately, didn't ever get it fixed. But I did manage to find a pretty simple workaround.
The tasks the generators perform are typically pretty straightforward. So manually reproducing the same result shouldn't be a big deal if you just take a look at the generator code.
The devise_install generator in your example above just copies devise.rb to config/initializers/devise.rb and en.yml to config/locales/devise.en.yml
If you take a look at the other generators I'm sure you can figure them out easily enough as well.
The same problem occurred with me, because I'm already had installed devise (a version ahead of 1.0.8). I just uninstall the devise ahead version.
Now my enviroment has only devise 1.0.8 and it works very well. :)
seems to be working using devise 1.0.7

Resources