Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm using the FedEx gem to pull down tracking numbers, the issue I'm running into is that if a tracking number has been generated, but not picked up, the gem returns a Fedex::RateError
According to the documentation Fedex:RateError inherits from StandardError I need to display a message if this error trips on the frontend site
I looked around online and found some ideas, but was hoping someone can point me in the right direction for handling errors, I'm using Rails 4.
Thanks for any suggestions
begin
# Do your normal happy path view stuff here
rescue Fedex:RateError => error
# Do your display of the error to the user here
end
Thanks msergeant, that did it!
Here's my final code- this recovery isn't very well documented and seems like a handful of people we're looking for it.
begin
results = fedex.track(:tracking_number => tracking)
rescue Fedex::RateError
statusImg = "http://t2.gstatic.com/images?q=tbn:ANd9GcRuKAIYZ2mNLsjRulsH05zNwF93jmAdpgZGSgtVN8XiT7_SWw285g"
statusRet = "Nope!!"
#trkResultTxt = statusRet
#trkResultImg = statusImg
else
tracking_info = results.first
#trkStatus = tracking_info.status
end
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
please I need a little help... I don't know what I'm doing wrong but I need just a simple select query with Active Record. This looks my code:
Model:
class Kiosk < ApplicationRecord
#kiosk = Kiosk.all
end
Controller:
class KioskController < ApplicationController
def kiosk
#kiosk = Kiosk.all
end
end
HAML:
##kiosk
And it just doing nothing. Even if I change a password of database there isn't any error with connection. rake db:migrade was done a db was created.
Thanks
You may want to look at your logs (eg Rails.root => logs/development.log) or the output in your terminal – are there any error messages? If you log in to your console with eg rails console and run #kiosks = Kiosk.all – what are you seeing? or how about Kiosk.count –– is it showing that there are any kiosks? As mentioned the model looks funny... not sure why you have the #kiosk = Kiosk.all line in there at all....
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
where does that #user in the code in check_ammo come from?
see code for "weapon" in model, controller, mailer and schema.rb
rails for zombies code
That code cant be right.
Weaponmailer
def low_ammo(weapon, zombie)
attachments["weapon.jpg"] = weapon.picture_file
mail to: zombie.email, subject: "#{weapon.name} has low ammo"
end
expects 2 parameters in controller
WeaponMailer.low_ammo(#user).deliver
#user is not defined unless its defined in ActiveRecord::Base what is not the case i think. Its just broken code example
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Is it possible to have JSON.parse work 2 layers deep so that a hash within a hash will get parsed as well? Is there a method for or do I have to do something like JSON.parse(JSON.parse(...)['foo'])?
JSON.parse doesn't care about your hash structure:
> str = JSON.dump({foo: {bar: {baz: :qux}}})
=> "{\"foo\":{\"bar\":{\"baz\":\"qux\"}}}"
> p = JSON.parse(str).with_indifferent_access
=> {"foo"=>{"bar"=>{"baz"=>"qux"}}}
> p[:foo][:bar][:baz]
=> "qux"
(Well, it cares if you have a malformed string, but that's something else altogether.)
So, what are you asking?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a parameter (params[:authorization]) that comes from the URL, as you can see:
authorization_selected = params[:authorization]
new_parcel = params[:new_parcel].to_i
puts authorization_selected.class (in the console show type String)
puts new_parcel.class (in the console show type Fixnum)
In my controller, have:
#portability = Portability.new
#portability.employee_id = authorization_selected.employee_id
However this returns an error:
undefined method `employee_id' for 3:Fixnum
I need that both was integer. How do it?
You are calling the employee_id method on authorization_selectedwhich is a String and does not provide this method.
Obviously this does not work. You probably want to do
#portability = Portability.new
#portability.employee_id = authorization_selected
assuming that params[:employee] contains the employee_id and Portability is an ActiveModel or an ActiveRecord.
Perhaps you can change your form that the value can be assigned through the initializer?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
If I have a form input where someone puts 'facebook.com' or 'google.com' it turns it into a valid URL adding http:// so that rails can use it. What I want is to have a form where you input a URL and it grabs the 3 most used words at that site and shows them in a list on the results page. This list should be accessible later, so I also need to store those words with that URL
def smart_add_url_protocol
url = Url.find_by(params[:url])
unless self.url[/\Ahttp:\/\//] || self.url[/\Ahttps:\/\//]
self.url = "http://#{self.url}"
end
end
something like this.
You can use URI::HTTP#build like so:
URI::HTTP.build(host: 'facebook.com').to_s
#=> "http://facebook.com"
I recommend the Addressable gem which is somewhat smart about guessing URLs from strings:
require "addressable/uri"
Addressable::URI.heuristic_parse(some_string_with_an_url).to_s