Rectangle 27 2

When I was trying to install Rack and Passenger from gem package manager I got the above error. I have tried various methods but it was not helpful for me. The below commands i have tried and it worked for me so far. i hope it helpful for you.

[vagrant@centos65 puppet]$ sudo gem install rack -v 1.6.0

Successfully installed rack-1.6.0

1 gem installed

Installing ri documentation for rack-1.6.0...

Installing RDoc documentation for rack-1.6.0...

[vagrant@centos65 puppet]$ sudo gem install rake -v 10.4.2

Successfully installed rake-10.4.2

1 gem installed

Installing ri documentation for rake-10.4.2...

Installing RDoc documentation for rake-10.4.2...

[vagrant@centos65 puppet]$ sudo gem install daemon_controller -v 1.2.0 

Successfully installed daemon_controller-1.2.0

1 gem installed

Installing ri documentation for daemon_controller-1.2.0...

Installing RDoc documentation for daemon_controller-1.2.0...

[vagrant@centos65 puppet]$ sudo gem install passenger -v 4.0.56

ruby on rails - Error while installing rack - Stack Overflow

ruby-on-rails ruby rubygems rack
Rectangle 27 100

This error means that the selected version of debugger does not support your current Ruby version. There are two solutions:

  • Update the debugger gem via bundle update debugger. New versions of debugger are backward-compatible with old Ruby versions, so this is the best way to fix it.

rubygems - Error installing debugger-linecache in Ruby 1.9.3 - Stack O...

ruby rubygems gem ruby-1.9.3
Rectangle 27 3

throw a error

You got an 404 because sinatra can't find a get route /users. If you want return a custom error you may look at Halt

The you can return a 405 on get /users like this:

get "/users" do
    halt 405
end
require 'sinatra'
require "sinatra/multi_route"
route :get, :post, '/foo' do
  # "GET" or "POST"
  p request.env["REQUEST_METHOD"]
end

# Or for module-style applications
class MyApp < Sinatra::Base
  register Sinatra::MultiRoute
  route :get, :post, '/foo' do
    # ...
  end
end

If you want handle error codes in sinatra you can simple do for 404 errors:

not_found do
  'This is nowhere to be found.'
end

In your case handle a 405 error:

error 405 do
  'Access forbidden'
end

So for every other verb that means I need to write a "halt 405"? That doesn't sound like an elegant solution. Technically, the resource/route exists, just the verb is wrong. Which is why I would expect a 405. There must be a better way to implement a catch all solution for 405's.

Hmmm, still not that elegant. It means I have to dirty my code with, route :get, :put :delete, :patch, :options, :and_so_on for every endpoint. But it's better than nothing, although I'd rather see if the core of the issue can be fixed.

you can may can catch some verbs with Before but it's still a lot repeating

ruby - Handling 405's in Sinatra - Stack Overflow

ruby sinatra
Rectangle 27 44

begin
  raise ArgumentError, "I'm a description"
rescue Exception => ex
  puts "An error of type #{ex.class} happened, message is #{ex.message}"
end

Prints: An error of type ArgumentError happened, message is I'm a description

And then if you still need specific handling for different types of errors, you can do that with a case..when.

Watch it, do not catch Exception unless you are completely aware of what it implies. Use rescue => ex instead(Convention over configuration) As a default cacher.

exception - How to display error type in ruby? - Stack Overflow

ruby exception
Rectangle 27 4

Rails 3.2.x: Can Handle Exceptions in Rack

I think you meant show, since index is really for lists/collections. And you should get .first on the where, otherwise you just have a relation, right? Then, use .first! to raise an error, because Rails' Rack middleware in Rails 4 public_exceptions will handle is in a basic fashion, e.g.

def show
  # need to do to_s on params value if affected by security issue CVE-2013-1854
  @bar = Bar.where(:foo_id => params[:id].to_s).first!
end

You can also use @bar = Bar.find(params[:id]), but that is deprecated and will be removed in Rails 4.1, after which you would have to add gem 'activerecord-deprecated_finders' to your Gemfile to use.

For index, you'd probably want @bars = Bar.all. If for some reason you want to filter and don't want to scope, etc., then you could use @bars = Bar.where(...).to_a or similar.

As long as the query kicks off an error, Rails 4 should be able to return the message part of the error for any supported format where to_(format) can be called on a hash (e.g. json, xml, etc.).

If it is html, it is going to try to read in the related file from the public directory in Rails for the status code (e.g. 500.html for a server error/HTTP 500).

If it is some other format, it will try to do to_(the format) on the hash: { :status => status, :error => exception.message }. To see how this would work go to Rails' console:

$ rails c
...
1.9.3p392 :001 > {status: 500, error: "herro shraggy!"}.to_xml
 => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n  <status type=\"integer\">500</status>\n  <error>herro shraggy!</error>\n</hash>\n" 
1.9.3p392 :002 > {status: 500, error: "herro shraggy!"}.to_json
 => "{\"status\":500,\"error\":\"herro shraggy!\"}"

In the middleware, you'll see the X-Cascade header in the code and in various places related to Rails' exception handling in Rack. Per this answer, the X-Cascade header is set to pass to tell Rack to try other routes to find a resource.

In Rails 3.2.x, that code to do to_(format) for the response body, etc. is not in public_exceptions.rb. It only handles html format.

Perhaps you could try replacing the old middleware with the newer version via a patch.

If you'd rather have Rack handle your error in a more specific way without a patch, see #3 in Jos Valim's post, "My five favorite hidden features in Rails 3.2".

config.exceptions_app = self.routes
config.consider_all_requests_local = false
config/environments/development.rb

You don't have to use routes to use exceptions_app. Although it may be a little intimidating, it is just a proc/lambda that takes a hash and returns an array whose format is: [http_status_code_number, {headers hash...}, ['the response body']]. For example, you should be able to do this in your Rails 3.2.x config to make it handle errors like Rails 4.0 (this is the latest public_exceptions middleware collapsed):

config.exceptions_app = lambda do |env|
  exception = env["action_dispatch.exception"]
  status = env["PATH_INFO"][1..-1]
  request = ActionDispatch::Request.new(env)
  content_type = request.formats.first
  body = { :status => status, :error => exception.message }
  format = content_type && "to_#{content_type.to_sym}"
  if format && body.respond_to?(format)
    formatted_body = body.public_send(format)
    [status, {'Content-Type' => "#{content_type}; charset=#{ActionDispatch::Response.default_charset}",
            'Content-Length' => body.bytesize.to_s}, [formatted_body]]
  else
    found = false
    path = "#{public_path}/#{status}.#{I18n.locale}.html" if I18n.locale
    path = "#{public_path}/#{status}.html" unless path && (found = File.exist?(path))

    if found || File.exist?(path)
      [status, {'Content-Type' => "text/html; charset=#{ActionDispatch::Response.default_charset}",
              'Content-Length' => body.bytesize.to_s}, [File.read(path)]]
    else
      [404, { "X-Cascade" => "pass" }, []]
    end
  end
end

Note: For any problem with that handling, the failsafe implementation is in ActionDispatch::ShowExceptions here.

If you'd rather have error rendering in the controller itself, you can do:

def show
  respond_with @bar = Bar.where(:foo_id => params[:id].to_s).first!
rescue ActiveRecord::RecordNotFound => e
  respond_to do |format|
    format.json => { :error => e.message }, :status => 404
  end
end
def show
  @bar = Bar.where(:foo_id => params[:id].to_s).first
  if @bar
    respond_with @bar
  else
    respond_to do |format|
      format.json => { :error => "Couldn't find Bar with id=#{params[:id]}" }, :status => 404
    end
  end
end

You can also use rescue_from, e.g. in your controller, or ApplicationController, etc.:

rescue_from ActiveRecord::RecordNotFound do |exception|
  respond_to do |format|
    format.json => { :error => e.message }, :status => 404
  end
end

Though some common errors can be handled in the controller, if you errors related to missing routes, etc. formatted in json, etc., those need to be handled in Rack middleware.

ruby - Rails proper way to display error with jbuilder - Stack Overflo...

ruby-on-rails ruby json jbuilder
Rectangle 27 21

You'll want to read up on ruby load path (either $LOAD_PATH or $:). By default, ruby has a load path which includes wherever your gems are installed, which is why you can do require 'haml' without providing the full path to where your haml gem is located.

When you type require 'haiku', you're basically telling ruby to look for some file called haiku.rb somewhere in it's load path, and the LoadError comes from ruby not finding your haiku.rb file in any of the directories listed in $LOAD_PATH (or $:, which is just shorthand for $LOAD_PATH).

You can solve this in one of (at least) two ways:

You might also look into require_relative if you're running ruby 1.9.

I don't think .append is a method on the $LOAD_PATH array. Should the code snippet in #2 be $:.push or have I got something wrong?

$:.push
$: <<

As a side note on the $:.push part, this will append the current directory to the end of the load path. In order to prepend it to the load path, use unshift instead of push

ruby on rails - Rack Error -- LoadError: cannot load such file - Stack...

ruby-on-rails ruby rack
Rectangle 27 43

begin
  raise ArgumentError, "I'm a description"
rescue Exception => ex
  puts "An error of type #{ex.class} happened, message is #{ex.message}"
end

Prints: An error of type ArgumentError happened, message is I'm a description

And then if you still need specific handling for different types of errors, you can do that with a case..when.

Watch it, do not catch Exception unless you are completely aware of what it implies. Use rescue => ex instead(Convention over configuration) As a default cacher.

exception - How to display error type in ruby? - Stack Overflow

ruby exception
Rectangle 27 33

tl;dr Recent versions of RVM, the Ruby Version Manager, include a utility to diagnose and resolve errors caused by outdated certificate files. See the article Installing Rails for instructions and advice. The RVM website explains how to install RVM.

$ rvm -v
# rvm 1.19.1 (stable)
$ rvm osx-ssl-certs status all
# Certificates for...
$ rvm osx-ssl-certs update all
# Updating certificates...

Thats all that is needed to resolve the issue if you are using RVM (you must be using RVM version 1.19.1 or newer).

And what about other systems? What kind of Mikey Mouse command syntax is that?

ruby - Error installing Bundler - Stack Overflow

ruby terminal gem bundler
Rectangle 27 33

tl;dr Recent versions of RVM, the Ruby Version Manager, include a utility to diagnose and resolve errors caused by outdated certificate files. See the article Installing Rails for instructions and advice. The RVM website explains how to install RVM.

$ rvm -v
# rvm 1.19.1 (stable)
$ rvm osx-ssl-certs status all
# Certificates for...
$ rvm osx-ssl-certs update all
# Updating certificates...

Thats all that is needed to resolve the issue if you are using RVM (you must be using RVM version 1.19.1 or newer).

And what about other systems? What kind of Mikey Mouse command syntax is that?

ruby - Error installing Bundler - Stack Overflow

ruby terminal gem bundler
Rectangle 27 16

The format for using rescue is as follows:

begin
  # Code you want to run that might raise exceptions
rescue YourExceptionClass => e
  # Code that runs in the case of YourExceptionClass
rescue ADifferentError => e
  # Code that runs in the case of ADifferentError
else
  # Code that runs if there was no error
ensure
  # Code that always runs at the end regardless of whether or not there was an error
end

Makes perfect sense- Thanks for the explanation, I was simply missing the begin piece.

@LeviStanley it's worth noting that you don't need begin keyword if you want to rescue all code of method.

You mean implicit exception blocks (like when defining a method) or something else?

@MarekLipka I added a link to another question; it includes a lot more information including mention of implicit exception blocks.

api - Ruby rescue syntax error - Stack Overflow

ruby api syntax-error rescue
Rectangle 27 52

This error generally happens when you accidentally recursively changing an attribute. If you have a username attribute in User model, and a virtual attribute named username, that is directly changing the username, you end up calling the virtual, the virtual calls the virtual again and so on.. Therefore, take a look on whether something like that happens somewhere in your code.

Stack level too deep error in Ruby on Rails - Stack Overflow

ruby-on-rails ruby
Rectangle 27 12

After looking at some of the answers to the Stack question @Matt referenced, although the error was different, one of the solutions also helped me for this problem.

In the home directory, create a file called .gemrc. Add :ssl_verify_mode: 0 to the file. Bundler then installs without issue.

This works for my situation as I'm behind a corporate firewall. However, this obviously opens up a security hole.

ruby - Error installing Bundler - Stack Overflow

ruby terminal gem bundler
Rectangle 27 12

After looking at some of the answers to the Stack question @Matt referenced, although the error was different, one of the solutions also helped me for this problem.

In the home directory, create a file called .gemrc. Add :ssl_verify_mode: 0 to the file. Bundler then installs without issue.

This works for my situation as I'm behind a corporate firewall. However, this obviously opens up a security hole.

ruby - Error installing Bundler - Stack Overflow

ruby terminal gem bundler
Rectangle 27 6

CC=clang rvm reinstall 2.0.0-p0

it will compile but might result in other errors later (I'm working on finding what causes the original issue).

CC=clang rvm reinstall "2.0.0-p0" Version '2.0.0' is to confusing to select ruby interpreter. Cannot remove unknown package '' Version '2.0.0' is to confusing to select ruby interpreter.

After doing 'rvm get stable' That would work too...

@mpapis please post updates if you find out what is the original cause. I had the same problem with rbenv as well, but changing CC seemed to help.

ruby - Error while installing ruby2 with rvm - Stack Overflow

ruby rvm
Rectangle 27 17

The stack level too deep error occurs also, if you want to destroy a record and you have an association with :dependent => :destroy to another model. If the other model has a association with :dependent => :destroy back to this model, the stack level is too deep, too.

belongs_to :model, dependent: destroy
has_many :other_model, dependent: :destroy

Stack level too deep error in Ruby on Rails - Stack Overflow

ruby-on-rails ruby
Rectangle 27 26

I've gotten this error when I updated to Ruby 2.0.0+ on Windows. I was able to solve it by uninstalling all versions of bcrypt that were downloaded, and building the gem using DevKit.

gem uninstall bcrypt-ruby

gem install bcrypt-ruby --platform=ruby --no-ri --no-rdoc

Usually doing a bundle update will download a precompiled gem mingw32 extension, which in this case appears not to work. This workaround for reinstalling bcrypt-ruby will hopefully not be needed in the future.

Some other Windows pitfalls you may run into are also listed there:

This works however it will get overriden when you do a bundle install. I solved it by installing it from github.

Thanks Remo, I had to bundle install, then remove the bcrypt gem and install as per your instructions.

gem install bcrypt-ruby -v 3.0.1 --platform=ruby --no-ri --no-rdoc

It still works only bcrypt-ruby changed its name to bcrypt. I'm so happy it still works.

bcrypt error: Devise ruby 2.0 and rails 4.0 - Stack Overflow

ruby-on-rails ruby devise gem bcrypt
Rectangle 27 20

i encountered the same error. It's introduced by sprockets-rails 2.1.4, that requires no more the /assets prefix for favicon_link_tag.

I fix it editing the Gemfile.lock, changing manually the version of sprockets-rails from 2.1.4 to 2.1.3 (in my specific case no gems require exactly that version, check your Gemfile.lock to be sure of that!!!).

This has already been fixed in spree master actually - github.com/spree/spree/commit/

Asset Path Error in Spree / Ruby on Rails - Stack Overflow

ruby-on-rails ruby spree
Rectangle 27 127

gem install debugger-linecache -v '1.1.2' -- --with-ruby-include=$rvm_path/src/ruby-1.9.3-p286/

Thank you; you're a lifesaver. This seems like a bug in... something. Probably rvm.

If you got no source for your ruby version (binary download) then you can do rvm fetch <ruby>

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

rubygems - Error installing debugger-linecache in Ruby 1.9.3 - Stack O...

ruby rubygems gem ruby-1.9.3
Rectangle 27 6

You can't run rvm command on Windows as you can see here, but you can fix the error without it. Just add a new source adress with http instead of https:

gem sources -a http://rubygems.org
gem install bundler

ruby - Error installing Bundler - Stack Overflow

ruby terminal gem bundler
Rectangle 27 6

You can't run rvm command on Windows as you can see here, but you can fix the error without it. Just add a new source adress with http instead of https:

gem sources -a http://rubygems.org
gem install bundler

ruby - Error installing Bundler - Stack Overflow

ruby terminal gem bundler