Trying to setup redis as session store - ruby-on-rails

I've been looking at different Gems for redis as session store but they seem to be throwing same/similar error that I can't get around.
For example gem 'redis-store' I add it to my gemfile. Here is the content of my session_store.rb initializer :
MyApp::Application.config.session_store Rack::Session::Redis
Here is the error I get while doing rails s :
/development/config/initializers/session_store.rb:5:in `<top (required)>': uninitialized constant Rack::Session::Redis (NameError)
Then I tried another gem redis-session-store. Here is the content of my initializer when using that gem :
MyApp::Application.config.session_store :redis_session_store,
:db => 0,
:expire_after => 10.minutes,
:key_prefix => "my_app:session:"
This is the error I get when starting my server :
/home/workstation/.rvm/gems/ruby-2.0.0-p353/gems/redis-session-store-0.2.1/lib/redis-session-store.rb:16:in `<top (required)>': uninitialized constant ActionController::Session (NameError)
I've never configured this before, can anyone point out what am I missing here?

It seems you should be using the redis-rails gem provided by the same user (redis-store that it). Looks like the one you're currently using is for rack-based applications.

Related

Cloudinary breaks RSpec tests with `uninitialized constant Cloudinary`

Have initialised Cloudinary using the ways described in this Rails integration article here >> https://cloudinary.com/documentation/rails_integration
Here is the error:
NameError:
uninitialized constant Cloudinary
# ./config/initializers/cloudinary.rb:3:in `<top (required)>'
I am using these gems:
gem 'cloudinary', '~> 1.13.2'
gem 'activestorage-cloudinary-service'
Have researched about this a lot but could not find any solution.
Cloudinary is recognised when on the development console but shows uninitialized when on the test environment console.
How do we make this work?

I cant run my rspec in Ruby on Rails

I cant really get going with my Rspec-gem :) Unfortunately. It seems like the Rspec-rails gem works differently now? Any idea?
This is my error Im getting:
testing_rspec/spec/models/transport_spec.rb:2:in `<top (required)>': uninitialized constant Transport (NameError)
from /Users/yoniPacheko/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load'
My spec file:
require 'spec_helper'
describe Transport do
end
This is my file
Thanks for yr time!
If this is a newly-generated app, you should be using require 'rails_helper', instead of requiring spec_helper.
rspec-rails 3 has split the two out so that spec_helper can be used for standalone Ruby code, and rails_helper (which includes spec_helper) can be used for testing code that relies on Rails.

Uninitialized constant ApplicationHelper::Twitter

What's up guys?
I'm using the Twitter-Text gem in my RoR project, but I'm having troubles with the ApplicationHelper. I already see another topics with this same question on StackOverflow, but no one fix my problem.
Ok, let's take a look at my project:
Gemfile
gem 'twitter-text'
Application_Helper.rb
module ApplicationHelper
require 'twitter-text'
include Twitter::Autolink
include Twitter::Extractor
end
// I really don't know why I need create the following file:
helpers/twitter.rb
module TwitterText
end
helpers/twitter_helper.rb
module TwitterText
end
controller/posts_controller.rb
require 'twitter-text'
include Twitter::Extractor
What I see in localhost error page:
Routing Error
uninitialized constant ApplicationHelper::Twitter
Try running rake routes for more information on available routes.
What I see in my console:
ActionController::RoutingError (uninitialized constant ApplicationHelper::Twitter):
app/helpers/application_helper.rb:3:in `<module:ApplicationHelper>'
app/helpers/application_helper.rb:1:in `<top (required)>'
app/controllers/application_controller.rb:1:in `<top (required)>'
It's appear to be everything ok, what can I do to fix this trouble?
Thanks a lot!
whenever installing new gems you have to restart your web server as your gems are loaded when the application environment starts. Those are installed to your global gem directory by doing a bundle install.

Rails undefined method `Initialize' in environment.rb

I am trying to integrate twitter/bootstrap in my very first rails app (followed this article http://www.opinionatedprogrammer.com/2011/11/twitter-bootstrap-on-rails/) and now I get this error which I am unable to understand/resolve.
new-host:Talker Talker$ rails s
=> Booting Thin
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Projects/Talker/config/environment.rb:4:in <top (required)>': undefined methodInitialize' for Rails:Module (NoMethodError)
from /Projects/Talker/config.ru:4:in require'
from /Projects/Talker/config.ru:4:inblock in '
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:51:in instance_eval'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:51:ininitialize'
from /Projects/Talker/config.ru:1:in new'
from /Projects/Talker/config.ru:1:in'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:40:in eval'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:40:inparse_file'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:200:in app'
from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/server.rb:46:inapp'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:301:in wrapped_app'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:252:instart'
from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/server.rb:70:in start'
from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:55:inblock in '
from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:50:in tap'
from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:50:in'
from script/rails:6:in require'
from script/rails:6:in'
This is how my environments.rb looks like
require File.expand_path('../application', FILE)
Rails.Initialize.run do |config|
config.gem 'mongo'
config.gem "mongo_mapper"
end
Talker::Application.initialize!
I am very new to rails so any help/direction is highly appreciated!
When following naren's instructions, have you removed the Rails.Initialize.run block from the environment.rb file? I know this probably may sound silly :)
Also, from the second error, I gather that you might be using Mongo HQ and if it is hosted on Heroku, they have a pretty detailed instruction manual on configuring your DB. Heroku MongoHQ Dev Center. Two things to check in your app:
Is the MongoDB url (Mongo HQ's url) is configured properly? This is because, the second error says that there may be a problem with the link itself.
Newer version of rails (3 and above) do not allow the config.gem syntax in the environment block. Rather, you need to add a initializer file in config/initializers. More on this on the MongoDB Documentation for Rails 3 section.
Hope this helps.
I think you do not need to specify config.gem in Rails.Initialize. In your Gemfile under project root directory specify the gems. You can remove the above
gem "mongo"
gem "mongo_mapper"
Then install gems using bundle install. Now you should be having the gems
Please try restarting after removing the Rails.Initialize block

Ruby on Rails Gitorious: uninitialized constant Rails::Plugin::OpenID

I am trying to setup gitorious yousource branch, I've followed partly this article: http://www.lacerta.be/d7/content/gitorious-ubuntu-natty
Everything was installed but I get this error:
Error message:
uninitialized constant Rails::Plugin::OpenID
Exception class:
NameError
Application root:
/var/www/gitorious
My Gemfile has gem "ruby-openid", :require => 'openid' but doesn't work anyway.
Anyone know how could i fix it?
Maybe you are not loading "ruby-openid" before the OpenID is called in Rails::Plugin namespace.

Resources