nameerror unitialized constant rails - ruby-on-rails

I am working on deploying a rails 5 api. After much trail error its almost functioning. The problem I am having is that I am running into a 500 server error. I sshed into the instance to check the logs and I keep getting this name error. The log output:
[2017-11-14T15:41:47.289647 #10484] INFO -- : [6d21f1c2-6770-42a2-93be-cd68ee0441fc] Completed 500 Internal Server Error in 244ms (Views: 0.2ms | ActiveRecord: 3.6ms)
F, [2017-11-14T15:41:47.290161 #10484] FATAL -- : [6d21f1c2-6770-42a2-93be-cd68ee0441fc]
F, [2017-11-14T15:41:47.290225 #10484] FATAL -- : [6d21f1c2-6770-42a2-93be-cd68ee0441fc] NameError (uninitialized constant Net::HTTP):
F, [2017-11-14T15:41:47.290245 #10484] FATAL -- : [6d21f1c2-6770-42a2-93be-cd68ee0441fc]
F, [2017-11-14T15:41:47.290263 #10484] FATAL -- : [6d21f1c2-6770-42a2-93be-cd68ee0441fc] app/models/user.rb:41:in `authorization'
[6d21f1c2-6770-42a2-93be-cd68ee0441fc] app/models/user.rb:17:in `create_new_auth_token'
I thought I forgot to require net/http, but when I check the require statement was already there. I'm not understanding this at all. Further, I checked the console and its showing that the package has been included. The code:
require "uri"
require "net/http"
def authorization(client_id, token)
encrypted_token = Digest::SHA256.hexdigest(token)
params = { "token": encrypted_token, "client": client_id }
Net::HTTP.post_form(URI.parse("path to api"), params)
end
Does anyone have any insight as to what is going on?

Related

twilio-ruby stops working after upgrading to ruby 3.1.3

I have been using the twilio api for 3 years to send messages and it worked perfectly. After upgrading from ruby 2.6 to ruby 3.1.3, Twilio is no longer working. We are using twilio-ruby 5.74.2. We are getting the error ArgumentError (wrong number of arguments (given 1, expected 0)):. I have the following code:
def send_pin_through_twilio
client = Twilio::REST::Client.new
client.messages.create({
from: ENV["twilio_phone_number"],
to: self.phone_number,
body: "Hello from ...! Your one-time pin is #{self.one_time_pin}."
})
end
We get the following error:
2023-02-03T17:11:25.312087+00:00 app[web.2]: F, [2023-02-03T17:11:25.311995 #4] FATAL -- : [0d0b1732-1dbc-4170-a3d3-ba99bb7a676e]
2023-02-03T17:11:25.312089+00:00 app[web.2]: [0d0b1732-1dbc-4170-a3d3-ba99bb7a676e] ArgumentError (wrong number of arguments (given 1, expected 0)):
2023-02-03T17:11:25.312089+00:00 app[web.2]: [0d0b1732-1dbc-4170-a3d3-ba99bb7a676e]
2023-02-03T17:11:25.312090+00:00 app[web.2]: [0d0b1732-1dbc-4170-a3d3-ba99bb7a676e] app/models/user.rb:157:in `send_pin_through_twilio'
2023-02-03T17:11:25.312090+00:00 app[web.2]: [0d0b1732-1dbc-4170-a3d3-ba99bb7a676e] app/controllers/api/v3/users_controller.rb:127:in `login_next'
2023-02-03T17:11:25.320370+00:00 heroku[router]: at=info method=PUT path="/api/v3/users/login_next" host=app.hiwave.co request_id=0d0b1732-1dbc-4170-a3d3-ba99bb7a676e fwd="73.179.143.247,108.162.212.48" dyno=web.2 connect=0ms service=2790ms status=500 bytes=307 protocol=https
Here is our initializer for reference:
Twilio.configure do |config|
config.account_sid = ENV["accountsid"]
config.auth_token = ENV["authtoken"]
end
How do I fix this?
Change this:
client.messages.create({
from: ENV["twilio_phone_number"],
to: self.phone_number,
body: "Hello from ...! Your one-time pin is #{self.one_time_pin}."
})
To this:
client.messages.create(
from: ENV["twilio_phone_number"],
to: self.phone_number,
body: "Hello from ...! Your one-time pin is #{self.one_time_pin}."
)
Note that the second example is not a hash, it is using keyword arguments.
This is caused by the separation of positional and keyword arguments in Ruby 3.
If you had updated to Ruby 2.7 then you would have received a warning about this rather than an error. By skipping from 2.6 to 3 you missed the warning and went straight to an error.
I'd say that's because you're using a hash as parameter while the method is now waiting for keyword arguments, try to replace the method call with this line:
client.messages.create(from: ENV["twilio_phone_number"], to: self.phone_number, body: "Hello from ...! Your one-time pin is #{self.one_time_pin}.")

devise_token_auth email sending issue

I'm using devise_token_auth in my app. When user registers, it automatically sends confirmation email.
from https://github.com/lynndylanhurley/devise_token_auth/blob/master/app/controllers/devise_token_auth/registrations_controller.rb
# ..code
unless #resource.confirmed?
# user will require email authentication
#resource.send_confirmation_instructions({
client_config: params[:config_name],
redirect_url: #redirect_url
})
# ..code
And I get 500 error.
I, [2016-09-01T12:32:06.142856 #15153] INFO -- : [07ca58ab-1797-4edb-99bb-c7d408bfd2c9] Completed 500 Internal Server Error in 31331ms (ActiveRecord: 8.4ms)
F, [2016-09-01T12:32:06.145874 #15153] FATAL -- : [07ca58ab-1797-4edb-99bb-c7d408bfd2c9]
F, [2016-09-01T12:32:06.146192 #15153] FATAL -- : [07ca58ab-1797-4edb-99bb-c7d408bfd2c9] Net::OpenTimeout (execution expired):
F, [2016-09-01T12:32:06.146249 #15153] FATAL -- : [07ca58ab-1797-4edb-99bb-c7d408bfd2c9]
F, [2016-09-01T12:32:06.146292 #15153] FATAL -- : [07ca58ab-1797-4edb-99bb-c7d408bfd2c9] /home/deploy/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/smtp.rb:542:in `initialize'
...
As you can see from the log it times out Net::OpenTimeout (execution expired):
But when I run User.last.send_confirmation_instructions from console it sends the email how it is suppose to be.
What am I suppose to do?
Thanks!
The problem was because of ipv6.
To fix it I had to edit /etc/gai.conf by uncommenting #precedence ::ffff:0:0/96 100 line

Object appears as existing and not at the same time

I've got some very strange issue which I cannot debug.
This is my code:
def find_order_and_payment
#payment = Spree::Payment.find_by_identifier(params['session_id'])
Rails.logger.info "payment_id #{#payment.id}"
#order = #payment.order
end
And this is the output:
I, [2014-01-17T16:39:43.084827 #12342] INFO -- : payment_id 187
I, [2014-01-17T16:39:43.090718 #12332] INFO -- : Completed 500 Internal Server Error in 448ms
NoMethodError (undefined method `id' for nil:NilClass):
app/controllers/payu_status_controller.rb:36:in `find_order_and_payment'
Line 36 is the line with Rails.logger. I don't understand, why I get correct id, but same line returns undefined method id? If I'll call above code from console everything works as expected.

NoMethodError users_url with devise (ajax)

I use devise 2.2.2 with rails 3.2.11
I use devise with ajax requests
I changed the following configuration in initializers/devise.rb
config.navigational_formats = [:json, :html]
config.http_authenticatable_on_xhr = false
when I submit an empty sign in request, I expect to get a json response with errors hash, but i get a 500 instead (see below for the trace) (it works fine with sign up request)
here are my routes (nothing special)
devise_for :users
the trace:
Started POST "/users/sign_in.json" for 127.0.0.1 at 2013-01-27 13:33:45 +0100
Processing by Devise::SessionsController#create as JSON
Parameters: {"user"=>{"email"=>"", "password"=>"[FILTERED]"}}
Completed 401 Unauthorized in 1ms
Processing by Devise::SessionsController#new as JSON
Parameters: {"user"=>{"email"=>"", "password"=>"[FILTERED]"}}
Completed 500 Internal Server Error in 40ms
NoMethodError (undefined method `users_url' for #<Devise::SessionsController:0x007fe88ddd9550>):
You are probably overriding after_sign_in_path_for and have a code path in there that returns nil.
This causes devise to fall back to its default behaviour and call users_url to get the path to redirect to.
Why do I think this? Because you are having the same error I had (and lost some hair over) and also this bug report contains the github usernames of many other people who have been humbled by this particular issue.

Problem with Rails 3 and AMF , rails3-amf, RocketAMF

im trying to get AMF to work with Rails3.
I have succesfully installed rails3-amf-0.1.0 gem and the RocketAMF-0.2.1 gem.
In my app there is a controller with the following code:
def getRandomCards
#incoming = params[0]
#cards = Cardvo.first
respond_with(#cards) do |format|
format.amf { render :amf => #cards.to_amf}
end
end
through a call from Actionscript i would like to return some data in amf format.
further more, as mentioned in the instructions for rails3-amf i did the following.
in my production.rb under config/environment i added the line
config.rails3amf.map_params :controller => 'CardvosController', :action => 'getRandomCards'
an my amf gateway got
config.rails3amf.gateway_path = "/gateway"
The problem is:
Any call from Actionscript / Flash raises the following
(taken from the log )
Started POST "/gateway" for 192.178.168.1 at Fri Nov 19 15:13:28 +0100 2010
Processing by CardvosController#getRandomCards as AMF
Parameters: {0=>100.0}
[1m[36mSQL (0.4ms)[0m [1mSHOW TABLES[0m
[1m[35mCardvo Load (0.2ms)[0m SELECT `cardvos`.* FROM `cardvos` LIMIT 1
Completed 200 OK in 13ms (Views: 0.9ms | ActiveRecord: 0.5ms)
NoMethodError (undefined method `constructed?' for #<RocketAMF::Envelope:0x39ba868>):
The Amf file is created but the method, which is in remoting.rb from RocketAMF could not be found.
I think the error is thrown at request_parser.rb from Rails3AMF asking for constructed?
# Wrap request and response
env['rack.input'].rewind
env['rails3amf.request'] = RocketAMF::Envelope.new.populate_from_stream(env['rack.input'].read)
env['rails3amf.response'] = RocketAMF::Envelope.new
# Pass up the chain to the request processor, or whatever is layered in between
result = #app.call(env)
# Calculate length and return response
if env['rails3amf.response'].constructed?
For me it seems it is looking at the wron class for the method.
Where
NoMethodError (undefined method `constructed?' for #RocketAMF::Envelope:0x39ba868):
the essential part is
RocketAMF::Envelope:0x39ba868
which should be
RocketAMF:ANOTHER_CLASS:Envelope:0x39ba868
Am i right and where the heck is the error ?
Any help would be appreciated!
chris

Resources