Sinatra with Kaminari: cannot load such file -- kaminari/sinatra - ruby

I want to realize pagination in Sinatra with kaminari.
My Gemfile looks like this:
source "https://rubygems.org"
gem "sinatra"
gem "activerecord", :require => "active_record"
gem "mysql2"
gem "padrino-helpers"
gem "kaminari", :require => "kaminari/sinatra"
my Sinatra config.ru has a Bundler.require.
However, Passenger displays the following error: cannot load such file -- kaminari/sinatra
I don't know what's wrong. There is not much documentation about kaminari with Sinatra, and the only bit i found was: "You need padrino-helpers and require kaminari/sinatra". And that's what i did.

Sinatra (~> 1.4.0) depends on rack (1.5.2), while kaminari (~> 0.13.0) depends on rack (~> 1.2.1). And since kaminari only began experimental support for Sinatra since version 0.13.0, there appears to be an impasse.

Related

Ramaze app won't load due to Rack version conflicts

When I run ramaze start I get this.
C:/mowes/ruby/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1990:in `raise_
if_conflicts': Unable to activate innate-2012.03, because rack-1.5.2 conflicts w
ith rack (~> 1.4.1) (Gem::LoadError)
Here's my gemfile
source 'http://rubygems.org'
ruby '1.9.3'
gem 'ramaze', "<= 2012.04.14" #old version
gem "innate", ">= 2012.03", "< 2012.11" #old version
gem 'sequel'
if defined? ENV['RACK_ENV'] == 'production' then gem 'pg' else gem 'sqlite3' end
gem "sentry-raven", :git => "https://github.com/coderanger/raven-ruby.git"
gem 'bcrypt-ruby'
gem 'rdiscount'
gem 'redcarpet'
gem 'pony'
gem 'bacon'
gem 'koala'
#source 'http://mirror1.prod.rhcloud.com/mirror/ruby/'
#gem 'nokogiri'
#gem 'capybara'
I'm using an outdated version of Ramaze and gem list says rack (1.5.2, 1.4.1)
How do I fix this?
Removing rack 1.5.2 should solve it.

Ruby / sinatra - How to ouput JSON

I'm trying to format my output as json. Here is a test code from http://www.sinatrarb.com/contrib/json.html :
require "sinatra"
require "sinatra/json"
# define a route that uses the helper
get '/' do
json :foo => 'bar'
end
# The rest of your classic application code goes here...
It shows me an "Application Error". Maybe it comes from the other files to launch the app. I'm using heroku(cloud). So I have a Gemfile :
source 'https://rubygems.org'
gem 'sinatra', '1.1.0'
gem 'thin'
Gemfile.lock :
GEM
remote: https://rubygems.org/
specs:
daemons (1.1.9)
eventmachine (1.0.3)
rack (1.5.2)
sinatra (1.1.0)
rack (~> 1.1)
tilt (~> 1.1)
thin (1.5.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.4.1)
PLATFORMS
ruby
DEPENDENCIES
sinatra (= 1.1.0)
thin
and Procfile :
web: bundle exec ruby web.rb -p $PORT
Did I miss something ?
You need to reference in your Gemfile json gem, e.g:
gem "json", "1.5.5"
And then you call .to_json on the object you want to output as JSON.

JRuby "no such file to load"

Using jruby-1.6.7 via rvm and gem version 1.8.24 I created a new project containing a Gemfile:
source 'http://rubygems.org'
gem 'google-api-client'
and a main.rb:
require 'google/api_client'
After
gem install bundler
bundle install
gem list
I get
addressable (2.2.8)
autoparse (0.3.1)
bouncy-castle-java (1.5.0146.1)
bundler (1.1.4)
extlib (0.9.15)
faraday (0.8.1, 0.7.6)
ffi (1.0.11 java)
google-api-client (0.4.3)
jruby-launcher (1.0.14 java)
jruby-openssl (0.7.7)
json (1.7.3 java)
jwt (0.1.4)
launchy (2.1.0 java)
multi_json (1.3.6)
multipart-post (1.1.5)
rack (1.4.1)
rake (0.9.2.2)
rubygems-bundler (1.0.2)
rubygems-update (1.8.24, 1.7.2)
rvm (1.11.3.3)
signet (0.3.4)
spoon (0.0.1)
But when I run ruby main.rb, it results in an error:
LoadError: no such file to load -- google/api_client
require at org/jruby/RubyKernel.java:1033
(root) at main.rb:1
On MRI everything seems to be working fine. The problem does not seem bound to any specific gem.
Can someone help me with this?
Unless you have JRUBY_OPTS=--1.9 in your environment, or you pass the --1.9 flag on the command line, JRuby will default to 1.8 mode, which means that you explicitly have to require 'rubygems' in main.rb before you load your gems.

Could not find sprockets-2.0.0.beta.10 in any of the sources

I am specifically intertested in #270. You can see it here: http://railscasts.com/episodes/270-authentication-in-rails-3-1
I've downloaded the code, unzipped it and I'm in the auth-before directory.
I run bundle install and I get
Fetching source index for http://rubygems.org/
Could not find sprockets-2.0.0.beta.10 in any of the sources
I've tried fixing it my self and I've gotten this:
Bundler could not find compatible versions for gem "sprockets":
In Gemfile:
sprockets (~> 2.0) ruby
sass-rails (~> 3.1.0.rc) ruby depends on
sprockets (2.0.0.beta.10)
My gem file looks like this:
source 'http://rubygems.org'
gem 'rails', '3.1.0.rc4'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Asset template engines
gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-script'
gem 'uglifier'
gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
What should I do to resolve this?
update:
I followed the suggestion below and removed the version number from sass-rails. When I run the update command I get the following:
Bundler could not find compatible versions for gem "railties":
In Gemfile:
sass-rails (>= 0) ruby depends on
railties (~> 3.1.0) ruby
rails (= 3.1.0.rc4) ruby depends on
railties (3.1.0.rc4
Remove the version limitation on sass-rails from your Gemfile, then run
bundle update sprockets sass-rails
Both sass-rails and sprockets have a stable release now.

Railties dependency issues when upgrading to rails 3.1

I have the following gemfile:
source 'http://rubygems.org'
source 'http://gems.engineyard.com'
gem 'rails', '~> 3.1.0.rc4'
gem 'sass-rails', :git => 'https://github.com/rails/sass-rails.git'
gem 'compass', :git => 'https://github.com/chriseppstein/compass.git', :branch => 'rails31'
gem 'fancy-buttons'
gem 'haml'
gem 'authlogic', :git => 'https://github.com/AndreasWurm/authlogic.git'#, :branch => 'rails3'
gem 'nokogiri'
gem 'bundler'
gem 'resque'
gem 'resque-meta'
gem 'jquery-rails'
gem 'rake', '~> 0.8.7'
gem 'eventmachine'
gem 'em-websocket'
gem 'json'
gem 'coffee-script'
gem 'uglifier'
Whenever I run bundle install, I get the following error:
Bundler could not find compatible versions for gem "railties":
In Gemfile:
sass-rails depends on
railties (~> 3.2.0.beta)
rails (~> 3.1.0.rc4) depends on
railties (3.1.0.rc4)
Can anyone suggest a solution?
Remove, or comment out, the following:
# , :git => 'https://github.com/rails/sass-rails.git'
Explanation: it has been a while since the last release candidate of Rails 3.1 has been released, a sass-rails gem has been released that works with 3.1 so no need to pull sass-rails from git, and sass-rails master is now looking forward towards Rails 3.2.
try bundle update, that worked for me... Maybe delete all gems, and update rails first, then put gems back and run bundle update again?

Resources