Uninitialized constant of gem - ruby-on-rails

I've installed JWT gem - https://github.com/progrium/ruby-jwt
There is gem 'jwt' in Gemfile, of course. Inspite on that, I have the error of
uninitialized constant HomeController::JWT
in HomeController
class HomeController < ApplicationController
def method1
#jwt_token = JWT.encode({.... })
end
end

I believe you need a require 'jwt'.
HTH

Related

Authority gem gives 'undefined method'

I'm getting undefined method 'authorize_actions_for' in the controller when using rails-api with the Authority gem. Any ideas what I need to include? Here's my code:
Gemfile:
...
gem 'authority', '~> 2.9.0'
gem 'rails-api', '~> 0.1.0'
...
app/authorizers/session_authorizer.rb:
class SessionAuthorizer < ApplicationAuthorizer
def deletable_by?(user)
user.sessions.include?(resource)
end
end
app/controllers/v1/sessions_controller.rb:
class V1::SessionsController < ApplicationController
authorize_actions_for Session
...
end
Include Authority::Controller
As we discussed on Github, authorize_actions_for is defined in Authority::Controller.
In a normal Rails app, that module gets included into ActionController::Base by Authority's railtie.rb. Apparently the railtie isn't being required when using rails-api (maybe the Rails constant isn't defined?).
You can include the appropriate module yourself, though:
class ApplicationController < ActionController::Base
include Authority::Controller
end

Rails: error in setup google-api-client

in Rails (rails 4.0.0 rc2, ruby 1.9.3p429), in the Gemfile i've the following line:
gem 'google-api-client', :require => 'google/api_client'
and then bundle install.
In a controller:
require 'google/api_client'
class PagesController < ApplicationController
def home
#client = Google::ApiClient.new
end
end
If i go to 127.0.0.1:3000 i've the following error:
NameError in PagesController#home
uninitialized constant Google::ApiClient
Anyone can tell me how integrate the ruby google api in rails?
Thanks
It is APIClient.new.
#client = Google::APIClient.new
You should also set the application name and version number or you get an ugly stdout when run your code. Like so :
#client = Google::APIClient.new(:application_name => "MyApplication",:application_version => "0.1")

Ruby require directive causes an error

Trying to create a simple flickr application using Ruby on Rails 3.2.3, I faced a problem. First I installed a gem called flickraw
sudo gem install flickraw
Then I tried to use it
require 'rubygems'
require 'flickraw'
class HomeController < ApplicationController
def index
end
def index2
end
def index3
end
end
And I got an error:
LoadError in HomeController#index
cannot load such file -- flickraw
Any suggestions?
You should not require gems from the controller. You should just add flickraw to your Gemfile
gem "flickraw"

uninitialized constant ApplicationController::Bitly

I have the bitly gem installed and am setting it up in my ApplicationController to use the API for version 3, but it is throwing the above error. Here is the beginning of my application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
Bitly.use_api_version_3
before_filter { #cart = find_or_create_cart_from_session }
before_filter { #bitly = Bitly.new('myusername', 'XXXXXX_API_KEY_XXXXX') }
You say you have the Gem installed, but do you have it included in your Gemfile? If the Gem isn't in your Gemfile your application won't find it, which will lead to uninitialized constant errors.

Auto_link with rails_autolink gem - undefined method

I'm trying to use the rails_autolink gem.
As usual, I added the gem declaration to my gemfile:
gem 'rails_autolink'
Then ran "bundle install", restarted my rails local server and
Then I added to my posts_controller the require before the class declaration
require 'rails_autolink'
class PostsController < ApplicationController
...
and used the auto_link method inside my create action
def create
#new_post = Post.new(params[:post])
if #new_post.content == ""
redirect_to posts_url
else
#new_post.content = auto_link(#new_post.content)
... #respond_to and save methods
end
end
end #end of my post controller
The thing is that when I try to create a post I have a undefined method on the auto_link method, any idea why ? Is it specific to the gem or is it because something else ?
This is a view helper which you're trying to use in a controller
#new_post.content = view_context.auto_link(#new_post.content)
In any other places you can use: ActionController::Base.helpers.auto_link(text)
I don't believe you need the namespacing. Try it again simply using:
auto_link(#new_post.content)

Resources