I keep getting the same error since I upgraded to:
gem 'twilio-ruby', '~> 5.0.0.rc4'
The call was successful set to Twilio, but the getting some error.
app/controllers/home_controller.rb:59:in `rescue in call'
require "rubygems"
require "twilio-ruby"
def call
#twilio = Twilio::REST::Client.new account_sid, auth_token
begin
#call = #twilio.account.calls.create({
:to => ,
:from => twilio_number,
:url => url,
:method => "GET",
:if_machine => "Hangup",
:timeout => "20"
})
# Getting current call status (seems like error here...!)
get_status(#call.sid)
rescue Twilio::REST::RequestError => error
#err_msg = error.message
puts #err_msg
#returned error is like below:
#NameError (uninitialized constant Twilio::REST::RequestError)
end
end
Code for getting current call status:
def get_status(sid)
#twilio = Twilio::REST::Client.new account_sid, auth_token
#call = #twilio.account.calls.get(sid)
puts "Process Status : " + #call.status
return #call.status
end
Please help to figure it out.
Thank you!
For version 5, Try Twilio::REST::RestError.
This is documented here:
There are new classes to rescue errors from. The new library now uses the Twilio::REST::RestError class.
Related
I have some code to routing my url (every user has is own addres like: domain.com/username)
The problem is I get some errors because my regex is too large(?)
How can I solve this?
$user_nick=user::getAllUserNick();//this return string like: username1|username2 etc.
$user_url_firstpage = new Zend_Controller_Router_Route_Regex(
'('.$user_nick.'+)',
array('controller' => 'ads', 'action' => 'category', 'page' => 1), array(1 => 'nick', 2 => 'page'), '%s/'
);
error log:
[28-Sep-2020 07:18:10 UTC] PHP Warning: preg_match(): Compilation failed: regular expression is too large at offset 83837 in D:\netbeans-projects\mysite\library\Zend\Controller\Router\Route\Regex.php on line 83
Recently upgraded a codebase to rails4 along with gems, now we're getting this error.
Failure/Error: it { is_expected.to ensure_inclusion_of(:usage).in_array(['Index', 'Slide', 'Body']).with_message("%{value} is not a valid usage") }
["Index", "Slide", "Body"] doesn't match array in validation
and here is the related model code
USAGES = ['Index', 'Slide', 'Body']
validates_inclusion_of :usage, :in => USAGES, :message => "%{value} is not a valid usage"
Is there something I'm missing? I don't understand why this is failing.
validate_inclusion_of uses allow_value internally. Admittedly, we should give you a better error message as to what's going on here, but you should be able to write the following tests to figure out what's happening:
it { should allow_value("Index").for(:usage) }
it { should allow_value("Slide").for(:usage) }
it { should allow_value("Body").for(:usage) }
it do
should_not allow_value("something else").
for(:usage).
with_message("%{value} is not a valid usage")
end
My guess is that shoulda-matchers isn't automatically interpolating the %{value} inside of your failure message. If this is true, then what I would do (after filing an issue) is extract the message to an i18n key, and then pass the name of the key to with_message instead.
worked for me -
expect { should validate_inclusion_of(:usage).in?(['a', 'b']) }
should try this -
validates :usage, inclusion: { :in => %w( Index Slide Body ), :message => "%{value} is not a valid usage" }
looks like I am losing 'San Francisco' at the start of the Update test in this example - not sure why - when I do a puts response.body at the end the Post Test everything looks ok - here is my flights_spec.rb:
require 'rails_helper'
require 'spec_helper'
require 'flight'
RSpec.describe FlightsController, type: :controller do
render_views
let(:flight0) { Flight.create(:destination => "Las Vegas") }
it "Get Test" do
puts 'Get Test'
get :index, :format => :json
puts "Body = " + response.body
expect(response.body).to include('Las Vegas')
end
it "Post Test" do
puts 'Post Test'
post :create, :flight => {:destination => "San Francisco"}
puts "Post status:" + response.status.to_s
expect(response).to redirect_to(assigns(:flight))
redirect_to(response.headers['Location'])
get :index, :format => :json
puts "Body = " + response.body
expect(response.body).to include("San Francisco")
end
it "Update Test" do
puts 'Delete Test'
get :index, :format => :json
puts "Body = " + response.body
expect(response.body).to include("San Francisco")
end
end
RSpec assumes that you are writing each test to be independent of the other tests. However, the way you have it here, Update Test relies on Post Test to create the data it needs. RSpec automatically undoes any changes you made between each test. You can think of each it block as resetting everything back to the initial state.
A quick fix would be to simply aim the delete at the Las Vegas object instead since this flight is already being recreated for each test because of the let statement:
it "Update Test" do
puts 'Delete Test'
get :index, :format => :json
puts "Body = " + response.body
expect(response.body).to include("Las Vegas")
# rest of your test
end
Also I just would note that you may run into issues with the let statement because it is lazily instantiated, meaning it may not actually create a Las Vegas flight until you actually try to use the flight0 variable in your test. You can fix that by simply adding a bang to the end, like this let!(:flight_0) {}.
If have some static pages in a tree structure. The ones at the first level are served using static_pages_controller.rb and in my routes.rb I have :
get '/static_pages/news' , :to => 'static_pages#news' , :as => 'news'
get '/static_pages/index' , :to => 'static_pages#index' , :as => 'index'
....
The above exist in
app\views\static_pages\news.html.erb
app\views\static_pages\index.html.erb
....
Now, I pasted some other static pages underneath the static_pages root:
app\views\static_pages\ermis\news.html.erb
app\views\static_pages\ermis\index.html.erb
....
I added in routes.rb this:
get '/static_pages/ermis/news' , :to => 'static_pages#news' , :as => 'news'
get '/static_pages/ermis/index' , :to => 'static_pages#index' , :as => 'index'
The above doesnt work because the actions already exist (parent folders). So I went the painful step of renaming the files to (there must be a better way though?!?)
app\views\static_pages\ermis\ermisnews.html.erb
app\views\static_pages\ermis\ermisindex.html.erb
....
and my routes.rb became
get '/static_pages/ermis/news' , :to => 'static_pages#ermisnews' , :as => 'ermisnews'
get '/static_pages/ermis/index', :to => 'static_pages#ermisindex', :as => 'ermisindex'
....
the controller is empty
class StaticPagesController < ApplicationController
end
Why cant the pages be served ? what am I missing?
When I click on
<%= link_to("Ermis", ermisnews_path, class: 'pictureTitle') %>
I get
"The action 'ermisnews' could not be found for StaticPagesController"
Here my routes.rb
Prefix Verb URI Pattern Controller#Action
root GET / static_pages#index
ermisindex GET /static_pages/ermis/index(.:format) static_pages#ermisindex
ermisnews GET /static_pages/ermis/news(.:format) static_pages#ermisnews
news GET /static_pages/news(.:format) static_pages#news
index GET /static_pages/index(.:format) static_pages#index
NOTE: I do not get an error when using link directly pointing to .erb files on static_pages
<%= link_to("News" , news_path , class: 'pictureTitle')
Question:
1) How can I use the same controller to also serve static pages underneath /static_pages eg. /static_pages/ermis
2) Am I obliged to actually rename the files to have them represent unique actions?
In route.rb, change your routes as:
resources :static_pages do
resources :ermis do
get 'ermisnews' , :on => :collection
end
end
match '/ermisnews' => 'static_pages#ermisnews', :as => :news
And then run rake routes.
Eventually I found a solution to my issue:
created the following namespace:
namespace :sp do
resources: ixanos
resources: ermis
end
created the following controllers
class Sp::IxanosController < ApplicationController
end
class Sp::ErmisController < ApplicationController
end
Placed the controllers under app/controllers/sp/
Created the directories app/views/sp/ixanos and app/views/sp/ermis and copied my files in them.
(*) This way I can have as many static pages as I want underneath the given roots (ermis and ixanos). I haven't tested the situation whereby I will have sub-directories like sp/ermis/dir1/dir2 ...
I am using Devise+Omniauth , and I defined my own doorkeeper strategy to add a language option
In config/initializers/devise.rb , I set up :
require 'omniauth/strategies/doorkeeper'
config.omniauth :doorkeeper, Rails.application.secrets.doorkeeper_app_id, Rails.application.secrets.doorkeeper_app_secret,
:client_options => {
:site => Rails.application.secrets.doorkeeper_url
},
:authorize_params =>{:lang => I18n.locale}
which initially set lang to :en ( default locale )
this works fine and send the lang options to the remote server for Doorkeeperprocessing
now, how can I change this parameter in my client calling controller ?
I tried to use :
def index
I18n.locale = :fr
Rails.application.config.middleware.use OmniAuth::Builder do
provider :doorkeeper, :setup => lambda{|env| env['omniauth.strategy'].options[:authorize_params][:lang] = env['rack.session'][I18n.locale] }
end
but I got an error :
RuntimeError (can't modify frozen Array):
app/controllers/home_controller.rb:7:in `index'
Is there any better way to do it ? thanks for help
I modified the config/initializers/devise.rb, adding :setup => true
require 'omniauth/strategies/doorkeeper'
config.omniauth :doorkeeper, Rails.application.secrets.doorkeeper_app_id, Rails.application.secrets.doorkeeper_app_secret,
:client_options => {
:site => Rails.application.secrets.doorkeeper_url
},
:authorize_params =>{:lang => I18n.locale},
:setup => true
and I modified my doorkeeper strategy, to include the setup_phase, in which I set the lang option to the current locale.
def setup_phase
request.env['omniauth.strategy'].options[:authorize_params][:lang] = request.params["locale"]
end