Undefined method 'login_at' with Sorcery and 0auth, rails 4 - ruby-on-rails

I'm trying to set up Oauth with this rails project, but everytime I click 'login with ...' in my view, it renders an undefined method error for 'login_at'. My Sorcery config file contains the specific external submodule
Rails.application.config.sorcery.submodules = [:remember_me, :external]
but I still can't get past that error, any help would be greatly appreciated

You also have to provide external providers to sorcery config, e.g.
Rails.application.config.sorcery.configure do |config|
...
config.external_providers = [:twitter, :facebook]
...
end

Related

In Ruby on Rails, how to intercept the Devise gem's email sending functionality and change it to call an API instead? [duplicate]

As my reputation is lower than 50, so Im not able to comment below the accepted answer in this post In Rails Devise gem how to modify the send_reset_password_instructions method? for more information.
I want to customize recoverable.rb in devise. I made a copy of it in my folder with path lib/devise/models/recoverable.rb. The problem is when request to send reset password instruction, I got error undefined method activerecord51? for Devise:Module. How do i solve this?
It seems my recoverable is not in Devise module. I tried a bit by making a copy of devise.rb in lib/ folder. But it doesn't help.
Can someone please help?
EDIT
Sorry for any inconvenience. At the moment Im just trying to pass more opts to the method send_reset_password_instructions.
Any idea about this?
How about do it in some rails initializer? Your are possibly overwriting the original class/module so all the other methods are gone.
# config/initalizers/devise.rb
Devise::Models::Recoverable::ClassMethods.module_eval do
def send_reset_password_instructions(your, params)
token = set_reset_password_token
send_reset_password_instructions_notification(token)
token
end
end

Ruby on Rails ActiveAdmin + TinyMCE error

I was following the guide I found online to put ActiveAdmin and TinyMCE together into use, but I encountered a strange error which I was not able to search up the solution for it.
One part of it was to add in this line to config/initializers/active_admin.rb:
config.register_javascript 'tinymce.js'
However, when I try to run the app, an error says:
/Users/RageBill/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/bundler/gems/activeadmin-5ebf476abd92/lib/active_admin/application.rb:49:in method_missing': undefined methodregister_javascript' for # (NoMethodError)
Any thoughts on how can I resolve this problem? Thank you very much :)
(P.S. my rails version is 5.1.3 if that would be helpful.)
I found:
https://github.com/activeadmin/activeadmin/issues/340
This sholud work:
ActiveAdmin.setup do |config|
config.register_stylesheet "//cdn.foo.net/example.css"
config.register_javascript "//cdn.foo.net/example.js"
# ...
end

Sorcery undefined method `login_at'

I'm trying to get auth for Twitter and Facebook by this guide https://github.com/NoamB/sorcery/wiki/External, but I've got a problem - undefined method 'login_at' for #<OauthsController:0xa99d6bc>. Frankly I can't find this function(login_at) in guide. How can I fix it?
Ensure that you have External submodule included in your Sorcery configuration:
Rails.application.config.sorcery.submodules = [:external, ...]

Testing facebook login with rails cucumber

I have set up Facebook login on my site following this tutorial and am using cucumber and capybara. I have tried following other SO posts like this that explain how to set up a fake login account. If I use this directly, I get:
When I follow "sign_in" # features/step_definitions/web_steps.rb:56
No route matches [GET] "/oauth/authorize" (ActionController::RoutingError)
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow "([^"]*)"$/'
features/facebook_signin.feature:9:in `When I follow "sign_in"'
If I add get "/oauth/authorize" to my routes, I get:
When I follow "sign_in" # features/step_definitions/web_steps.rb:56
uninitialized constant OauthController (ActionController::RoutingError)
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow "([^"]*)"$/'
features/facebook_signin.feature:9:in `When I follow "sign_in"'
I don't know what is going on and why it is complaining. If I change my Gemfile from gem 'omniauth-facebook', '1.4.0' to just gem 'omniauth-facebook' I get virtually the same errors above except instead of:
/oauth/authorize, I get /dialog/oauth and instead of uninitialized constant OauthController, I get uninitialized constant DialogController
Has anyone recently successfully set up cucumber testing for login with Facebook?
When I am on localhost:3000 and navigate to localhost:3000/auth/facebook everything works and I am using a sessionsController so I don't understand why in testing, it is trying to use these oauthControllers or DialogueControllers.
I recently had the same issue or a very similar issue:
ActionController::RoutingError:
No route matches [GET] "/dialog/oauth"
I had taken the working specs which properly set up mock responses from another project and was pretty surprised to suddenly get this error.
After much pain and suffering I had a major facepalm moment when I realized i had forgot to set OmniAuth to use test mode:
# spec/rails_helper.rb
OmniAuth.config.test_mode = true
This will cause OmniAuth to short circuit so that you can set the auth responses by:
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({
:provider => 'facebook',
:uid => '123545'
# etc.
})
I think the error is due to OmniAuth trying to be helpful by using the :developer strategy in the test environment so that you don't get banned by the auth provider.
See https://github.com/intridea/omniauth/wiki/Integration-Testing.
Have you enabled Javascript in this tests? As the tutorial mentions the facebook.js.coffee?
describe 'When I follow "sign in"', js: true do
Another possibility is that you included the gem only in the development block of the Gemfile
group :development do
gem 'omniauth-facebook'
end
BTW: you shouldn't be testing against "real" external endpoints. Take a look at webmock for this kind of tests to mock the Facebook response
I had to put #omniauth_test_success before the feature and not the step definition. Additionally, I had to fix some routing issues. Will post full report later this week.

How can I fix this undefined method error?

I am integrating Postmark's transactional email service into my web application so that when a user signs up, my application sends the user a welcome email. When I try to signup as a user, I get the following error: undefined method `postmark_settings=' for ActionMailer::Base:Class
In my config/application.rb file, I have the following code:
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_key => "my_api_key" }
I'm not sure what is causing the error or how I can go about fixing it. If I haven't provided enough useful information to solve the problem, just let me know and I'll add whatever code might be useful. Thanks so much!
Have you included the line below in your Gemfile?
gem 'postmark-rails', '0.4.0'
There are similar issues where people haven't included this line on the Gemfile...
Also, are you using Rails 3? The configuration in different between Rails 2 and 3. Please note details here.

Resources