NoMethodError when attempting to use open_id_authentication - ruby-on-rails

I'm currently adding OpenID login support for a Rails 3.0.0 application.
I have already installed ruby-openid (the gem) and open_id_authentication (the plugin). However, after following the steps required to set up both (from the READMEs), I am still getting this error:
undefined method `authenticate_with_open_id'
I tried Googling the problem, but most threads seem to date from years ago and remain suspiciously unanswered.
Am I missing something obvious? What is causing this problem? Note that I have had no problems switching to file-based stores in environment.rb, so I am sure that the plugin is correctly installed.
Update: Some unresolved problems of the same nature:
http://railsforum.com/viewtopic.php?id=23151

Experiencing a similar error; oddly, I have this working on Rails 3.2 on another branch, and can't figure out the difference; anyhow I found that I got a little further by following suggestions here: Rails 3.0.9 + open_id_authentication
That is, adding the line include OpenIdAuthentication after class SessionsController < ApplicationController:
class SessionsController < ApplicationController
include OpenIdAuthentication
But now I get a Completed 401 Unauthorized in my log, and see a blank page -- just and tags. Ugh.
Update: Ooh, got further; I followed this post: open_id_authentication - "OpenIdAuthentication.store is nil. Using in-memory store." problem
and as they suggested, "added an initializer named config/initializers/openid.rb with this inside":
require 'open_id_authentication' # this was needed, but not described in the referred-to post
OpenIdAuthentication.store = :file
I was then directed to the OpenId provider and was able to click "allow", but on returning to my app, I now see:
NoMethodError in SessionsController#create
undefined method `encoding' for nil:NilClass
Anyhow, finally, I found a restful routes problem and fixed that, and now logging in works!

Related

Enabling CORS for IGDB using ruby on rails?

So I've been at this issue for hours now but cannot figure it out. I've been trying to use the IGDB API using the ruby gem igdb_api but keep getting a 403 Forbidden exception. I'm running the server locally for development at localhost:3000. Here is how I setup my test code:
class PagesController < ApplicationController
def home
...
end
def games
# initialize with api_key
Igdb.connect(ENV['IGDB_API_KEY'])
puts Igdb::Game.count
end
end
I've been trying to use rack-cors to fix this but nothing changes. So I'm not sure if I'm missing something obvious. Any help would be great! Thank you.
I don't think cors is an issue.
CORS basically prevents web-browser from making requests to services outside of current domain.
403 errors means some authorization problems.
I ended up using a different gem for accessing the api, one called igdb_client.
While I then had a SSL_connection error since I'm on Windows, it was easily fixed by following this quick solution here: https://superdevresources.com/ssl-error-ruby-gems-windows/.
Hope it'll help anyone in the future!

undefined method 'authorize' with Pundit

I've installed the gem Pundit in my Rails app, and have followed the instructions in the README carefully.
However, when I use authorize in any of my controllers, I get the error message "undefined method 'authorize' for .
Also, when I try to use "policy" in a view, I get the error "undefined method 'policy'".
It's as if Pundit weren't installed at all!
I've included Pundit in my Application Controller.
I have an ApplicationPolicy file with all of my policies, then policy files for each type of record that inherit from the Application Policy.
For some reason, I can't paste any of my code into this question, so I'm hoping I've included enough information!
I'd appreciate any thoughts.
I have recently used pundit and it worked like a charm.
your error messages makes me infer that you've not run install
rails g pundit:install or your policies file are not in correct directories.
or if they are then Just restarting the server should fix this. Hopefully.
For me, I was missing include Pundit at the top of my ApplicationController. Adding that line fixed it.
You need to generate a default policy file for your application with the pundit:install generator.
rails g pundit:install
create app/policies/application_policy.rb

Rails4 rails-api test: undefined session_serializer when testing auth via headers token

I have written a small app in order to practice with minitest. The stack is versioned as
follows:
Rails 4.1.4
ruby 2.1.2p95
devise 3.2.4
devise_token_auth 0.1.25
rails-api 0.2.1
The app has been generated from scratch as per rails-api instruction, and I can see
everything works as expected from the client side.
The difficutly I'm encountering is with controller's tests that have to deal with
authentication.
I took inspiration for this kind of test from:
https://github.com/lynndylanhurley/devise_token_auth/blob/master/test/controllers/demo_controller_test.rb
My test code is located at: http://pastebin.com/iPVk9Tzq
When I run the test suite I get back the following error:
PostsControllerTest#test_get_index_is_successful_if_logged_in:
NoMethodError: undefined method `session_serializer' for nil:NilClass
test/controllers/posts_controller_test.rb:24:in `block in <class:PostsControllerTest>'
I tried different searches over the net but I wasn't able to figure out how to solve
this issue.
I understand that the error happens because there's no session stored anywhere since the application is implemented as a stateless API.
Obviously if I comment out the "request.headers.merge! ..." line, the error disappear
and the test fails with a response of 401 (as it should when the user is not logged in).
Any help/suggestion is widely appreciated!
Regards
It turns out I simply forgot to include Devise::TestHelpers in my controller test class ...
Sorry :/

Starting out with vote_fu

Trying my luck with the vote_fu rails plugin. The functionality looks like exactly what I need for a project of mine, but I have hit a roadblock. I have followed the github readme to the letter, installing it as a plugin.
I have put acts_as_voteable on my "Event" model and acts_as_voter on my User model.
In the console, when I try:
>> event.votes
or
>> user.votes
it successfully returns an empty array.
but when I try to do the following:
user.vote_for(event)
I get
"NoMethodError: undefined method `user_id' for #<Vote:0x7f5ed4355540>"
Any ideas? I'm probably just missing something obvious, but maybe something is missing from the plugin's readme.
Thanks.
[Update]
I created a blank application and the plugin works fine, so I think that this problem might be being caused by the use of the "desert" plugin, as my User class is split over two files. If I find the answer, I'll post it so that in the off chance someone else runs into this it may be some help.
Cheers.
Ok, I haven't found a definitive reason why this problem occurred, but I do have strong suspicions that it is due to the use of the "desert" plugin, as my User class is split over two files (the project is using the CommunityEngine plugin as a base),
Anyhow, I found a work around (something I should have tried before posting here). Instead of installing vote_fu as a plugin, I installed it as a gem. And now vote_fu seems to be humming along nicely.
So let that be a lesson to you all!
:-P

Error while using Fetcher plugin to process incoming mail with Rails?

I'm trying to get a basic example app running that processes email. Nothing fancy, just the barest of functionality at this point. I've installed Fetcher, configured the YAML, updated the :receiver, and created an IncomingMailHandler class.
When I go to start the FetcherDaemon, I get the following error.
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:105:in `const_missing': uninitialized constant MailerDaemonFetcherDaemon::IncomingMailHandler (NameError)
I'm using Rails 2.3.2, with the latest Fetcher plugin. The IncomingMailHandler class in my models dir looks like this:
class IncomingMailHandler < ActionMailer::Base
def receive(email)
logger.info("Got a mail about: #{mail.subject}")
end
end
Help!
Ok, so basically, I'm a dumbass. I was following instructions all over the damn web, except for the mostly cut and dry explanation on github. Days later now, I just went through the motions, and boom, it worked flawlessly.
So, to anyone that finds this with the same problem (whether you were trying to follow the WAY outdated instructions on the PeepCode tutorial, or found some tips on a blog), don't be a dumbass like me. The most up-to-date info is on github.
Thanks to anyone that looked at this!
My guess is you didnt set the MailFetcher
MailFetcher.mailer_class = :incoming_mail_handler
put this in environment.rb after the RailsInitializer block.
If you want to use POP3 instead of IMAP you have to specify this there as well

Resources