I want mount Resque on a subpath in your existing Rails 4 - resque

rails3 resque(1-x-stable) I do like this at my routes.rb :
require 'resque/server'
mount Resque::Server.new, :at => "/resque"
but now I use rails 4 resque(2.0.0.pre.1), it has same problems like this:
uninitialized constant Resque::Server (NameError)
What can I do ?

the version 1.25.2 of the gem works well in rails 4.
You need to change this line
gem "resque", "~> 2.0.0.pre.1", github: "resque/resque"
by this in your gemfile
gem "resque"
and remove require 'resque/server' from your routes.rb

Related

Why do I get NameError with `bundle exec ruby [file]` given that the necessary gem is in Gemfile?

I'm doing some messing around to try to understand better how bundler works. I have just three files in my working directory:
Gemfile Gemfile.lock test.rb
All the Gemfile has is gem "slop" and test.rb looks like this:
puts Slop.parse
When I run bundle exec test.rb I get a NameError due to not having a require statement:
[ec2-user#xx my_app]$ bundle exec ruby test.rb
test.rb:1:in `<main>': uninitialized constant Slop (NameError)
But if I run bundle console, Bundler loads the gem correctly and I can run Slop.parse from the console without having to explicitly type require "slop":
[ec2-user#xx my_app]$ bundle console
irb(main):001:0> Slop.parse
=> #<Slop::Result:0x00000001339838...
So what am I missing? I was under the impression that since I don't have require: false in my Gemfile, Slop should be loaded when I run bundle exec ruby test.rb and I shouldn't need to put the require "slop" line in the file.
You need to config bundler to require all gems on your Gemfile like this:
require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
Check the docs at http://bundler.io/v1.12/bundler_setup.html
I was under the impression that since I don't have require: false in
my Gemfile, Slop should be loaded when I run bundle exec ruby test.rb
and I shouldn't need to put the require "slop" line in the file.
The bundler docs say:
Specify your dependencies in a Gemfile in your project's root:
source 'https://rubygems.org'
gem 'nokogiri' #<======HERE
Inside your app, load up the bundled environment:
require 'rubygems'
require 'bundler/setup'
# require your gems as usual
require 'nokogiri' #<========AND HERE
As for this:
I was under the impression that since I don't have require: false in
my Gemfile, Slop should be loaded when I run bundle exec ruby test.rb
and I shouldn't need to put the require "slop" line in the file.
The bundler docs are horrible on this point. As far as I can tell, :require => false is a Rails specific thing, which is used to decrease load times on project startup. In a rails app, specifying require: false means that the gem won't be loaded until you manually require the gem. If you don't specify :require => false, then the gem will be loaded automatically--however that is because rails code is written to do that automatic loading. Your app has no code that performs a similar function.
Edit: Made a mistake while testing. So here's the way it works: In a non rails app, e.g. in your test.rb, if you want to automatically require all the gems specified in your Gemfile, you need to write:
Bundler.require :default
The Bundler docs mention that in the fine print here:
Specify :require => false to prevent bundler from requiring the gem,
but still install it and maintain dependencies.
gem 'rspec', :require => false
gem 'sqlite3'
In order to require gems in your Gemfile, you will need to call Bundler.require in your application.
I'm not sure why that requirement was only mentioned in conjunction with require: false instead of being stated at the outset.
And, in your Gemfile if you specify:
gem 'slop', :require => false
(as well as Bundler.require :default in test.rb), then you also have to explicitly require the slop gem in test.rb:
require 'slop'
In other words, Bundler.require :default automatically requires all the gems in your Gemfile except the gems marked with require: false. For gems marked with require: false, you have to manually write require 'gem_name' in your app.
Therefore, neydroid posted the correct solution.
* In your Gemfile, you can nest gems in groups, which affects how Bundler.require() works. See the Bundler docs on groups.
You should add the require "slop" inside your test.rb

will_paginate helper undefined in sinatra with mongoid

I am using sinatra 1.4.3 and mongoid 3.1.4. I tried adding will_paginate gem from master branch for mongoid support so I added this to my gemfile:
gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git',
:branch => 'master'
In environment.rb I added:
require 'will_paginate'
require 'will_paginate/mongoid'
And pagination method started working. I have still problem with will_paginate helper. In my views I get errors like:
NoMethodError: undefined method `will_paginate' for #<Class:0x006ff5df8578b0>
Am I missing something for helper to work under sinatra?
I don't know if it's best solution but adding
include WillPaginate::Sinatra::Helpers
in my controller solved my problems.

undefined method `has_attached_file error paperclip

I am trying to use paperclip without rails(but trying to connect db created by rails).
Using bundler to require gems.
here are my models
class RailsDB < ActiveRecord::Base
establish_connection $db_config[:rails_db]
end
class VoiceCall < RailsDB
belongs_to :campaign
set_table_name :voice_calls
has_attached_file :sound_file
validates_attachment_presence :sound_file
end
If I try to run the program it throws the error
undefined method `has_attached_file
any idea y?
Edit:
my gem file
source "http://rubygems.org"
gem 'activerecord', '< 3.1', :require => 'active_record'
gem 'mysql2', '< 0.3'
gem "paperclip", "~> 2.4"
I require gems using
require "bundler/setup"
Bundler.require(:default)
One more observation. I started irb and required active record and then paperclip. and ran this
p ActiveRecord::Base.methods.select{|m| m =~ /has_attached_file/}
It returns empty list.
but when I open rails console (using "rails c") the statement works and returns the value.( Both are using same gems)
This error means the Paperclip gem is not loaded correctly (or at all) within your application.
Can you post your Gemfile and config/preinitializer.rb?
Is bundler working to successfully load other Gems in your environment?
I've seen this happen when Bundler was not configured correctly for a Rails project causing gems to fail to load. The paperclip model references are the canary in the coal-mine for this larger problem.
had the same issue.
using
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
instead helped out.

Bundler gem installed from github get installed in a different location

I am trying to install a gem from github like this:
gem 'omniauth', :git => "git://github.com/intridea/omniauth.git", :require => "omniauth"
The problem is that the gem is not actually being loaded. The ruby objects are not there.
So, bundle show omniauth shows me: Users/felipe/.rvm/gems/ruby-1.9.2-p136/bundler/gems/omniauth-5972c94792cf
The problem is that the gem is being installed to a different location from the regular ones. I expected it to be `/Users/felipe/.rvm/gems/ruby-1.9.2-p136/gems/``
Any idea on how to fix this?
I think you're missing these two lines:
require "rubygems"
require "bundler/setup"
as you can see in Bundler's source code, "bundler/setup" is going to put gems managed by Bundler in the Ruby's load path:
https://github.com/carlhuda/bundler/blob/1-0-stable/lib/bundler/setup.rb#L22
Hope this helps :)
try changing the bundler line to.
gem 'omniauth', :git => "git://github.com/intridea/omniauth.git", :require => 'oa-oauth'
The problem is that your :require property was pointing to the wrong file to load. It is not always the same name as the library, by the way, when both lib name and require are the same you don't need to specify it, only when they differs.

Rails 3 Authlogic - 'acts_as_authentic' undefined

I'm getting the following error:
NameError (undefined local variable or method `acts_as_authentic' for #<Class:0x1037e6310>):
app/models/user.rb:2
app/controllers/user_controller.rb:3:in `new'
I'm using Rails 3.0.0, with Ruby 1.8.7. Authlogic is in my Gemfile as follows:
gem 'authlogic', :git => "git://github.com/binarylogic/authlogic.git"
The entire contents of my User.rb file are as follows:
class User < ActiveRecord::Base
acts_as_authentic
end
I get the same error whether through 'rails console' or through the server. I have restarted the server more times than I can count. Please help, I can't figure it out.
Use a version of authlogic patched for Rails 3
gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3'
Or even better. Use Devise
Is the Authlogic Gem installed ?.
Please do
Bundle install
this should solve your problem.
gem "authlogic", "2.1.6"
Then
Bundle install
Hope it'll helpfull for you. :)
create a file in config/initializers as restful_authentication.rb
and paste this inside the file and restart server and try
require 'authenticated_system'
require 'restful_authentication/authentication'
require 'restful_authentication/authentication/by_password'
require 'restful_authentication/authentication/by_cookie_token'
require 'restful_authentication/authorization/aasm_roles'
require 'restful_authentication/authorization/stateful_roles'
require 'restful_authentication/trustification/email_validation'

Resources