How can I fix this undefined method error? - ruby-on-rails

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.

Related

Rails google-ads-ruby setting up

I am trying to use the google-ads-ruby library to allow our ruby on rails application users to connect our app with Google Ads and pull some stats from their account for them.
I installed the gem and managed to authenticate a user and get the refresh_token.
Now I'm trying to start collecting data from Google.
The first thing that fails is their instructions to require the gem in my code with require 'google/ads/google_ads'
I tried adding it to my controller and got cannot load such file -- google/ads/google_ads
Then, according to their instructions, I should be able to run this:
client = Google::Ads::GoogleAds::GoogleAdsClient.new do |config|
config.client_id = Rails.application.secrets.google_oauth_client_id
config.client_secret = Rails.application.secrets.google_oauth_client_secret
config.developer_token = Rails.application.secrets.google_developer_token
config.refresh_token = #user.google_ads.refresh_token
end
accessible_customers = client.service.customer.list_accessible_customers().resource_names
accessible_customers.each do |resource_name|
puts "Customer resource name: #{resource_name}"
end
and then list, for example, the user's accounts, as described here.
However, I am getting uninitialized constant Google::Ads::GoogleAds
Does anyone know what is going on?
Have you tried?
client = ::Google::Ads::GoogleAds::GoogleAdsClient.new do |config|
config.client_id = Rails.application.secrets.google_oauth_client_id
config.client_secret = Rails.application.secrets.google_oauth_client_secret
config.developer_token = Rails.application.secrets.google_developer_token
config.refresh_token = #user.google_ads.refresh_token
end
This is not really an answer to my question. I was unable to find a solution, but doing some more digging, I found the AdsWords on Rails example app Google added to that same gem and the documentation
The app is slightly outdated and you will probably hate getting it to work. Also, it's written in a very cryptic way and includes so many functions just to use their API... but I was able to make it work. To be honest, someone should write a tutorial.
Hope this may give some clues to someone who's lost at some point.

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

ahoy events Post error in rails

I started code rails recently and I need to figure out this problem.
I use this function especially for my project. So i customize name and properties variables.
ahoy.track(name, properties);
In local there is no problem but in the live version when the tracking method runs i received 404 error. This line create A POST request to /ahoy/events and there is no path /ahoy/events in the live version.
Hi everyone i try a lot and finally i found solution. Meanwhile this issue helped me a lot.
I modify only two files in my project.
ahoy.rb
mattr_accessor :auto_mount
self.auto_mount = false
routes.rb
mount Ahoy::Engine => "/ahoy", as: :my_ahoy
The Ahoy routes get activated only when Ahoy.api is true. In config/initializers/ahoy.rb make sure to have
Ahoy.api = true
ref here

Put gem class into namespace

To my Rails Gemfile I added a new gem. It is used like this:
Email::Client
The issue I'm having right now is that I also have a class in my rails app that's called Email. Now sometimes when I try to initialize it I get the following error:
Email.new # >> undefined method 'new' for Email:Module
Probably because Email is a Module in the gem. How can I fix this issue? Is there a way to namespace the gem module? I don't want to rename my Email class.
I don't want to rename the Email-Class.
Yet this is what you'll have to do. Your code is the only thing you control. Either rename/alias it (MyEmail) or namespace it (MyApp::Email).
Btw, you got off easy this time. Imagine what'd happen if the other Email was also a class. Suddenly, all your methods are gone. You add or change a method and your email doesn't see it. This could make for a frustrating debugging session.

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

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

Resources