How to fix NoMethodError undefined method `escape' for URI:Module? - ruby-on-rails

I'm following this guide for implementing the PayPal REST API in my Rails app, and it gives an error that's said in the title, specifically pointing to this line in the code under create_order.
response = #client.execute request
I'm sure I have my client id and secret copy pasted and I also copy pasted most of the code to avoid any errors. What's causing this problem and how do I fix it? I appreciate the help.
Edit:
Command line output:
Started POST "/create_order" for ::1 at 2021-11-16 21:21:07 +0800
Processing by BookingsController#create_order as */*
Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms | Allocations: 1603)
NoMethodError (undefined method `escape' for URI:Module):
app/controllers/bookings_controller.rb:35:in `create_order'

Probably best to just do a monkey patch with future expectation of moving away from paypal-checkout-sdk (it's deprecated)
monkey patch option can be found at:
paypal-checkout-sdk breaks in ruby 3.0.1

you are missing gem files which are required to use the URI.escape
add these gems in you gemfile
gem 'uri'
gem 'net-http'
gem 'http'
after that
run command => "bundle install" in the terminal
and then try to run you application via rails s
hope this will fix your error
Since "URI.escape" is depriciated by the ruby community but "paypal-checkout-sdk" uses it while requesting from client.
which is like this: #client.execute request

Related

Setting up ruby on rails 500 Internal Server Error

I decided to learn ruby on rails today. I did:
gem install rails
rails new <name>
cd <name>
rails server
Just like http://rubyonrails.org/download/ said to, and everything looked fine until I went to localhost:3000 on chrome I got "ERR_CONNECTION_REFUSED" and got nothing server side. Then I did:
wget localhost:3000
and got this client side (the terminal window running wget):
--2016-01-16 23:08:43-- http://localhost:3000/
Resolving localhost... fe80::1
Connecting to localhost|fe80::1|:3000... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2016-01-16 23:08:43 ERROR 500: Internal Server Error.
and this server side (the side running rails server):
Started GET "/" for fe80::1%o0 at 2016-01-16 23:08:17 -0500
sorry if this is obvious I am a web scrub :)
EDIT:
when I launch it says "WEBrick::HTTPServer#start: pid=35515 port=3000" so I assume that means it's on the right port
EDIT:
development.log:
Started GET "/" for fe80::1%lo0 at 2016-01-16 23:08:17 -0500
Started GET "/" for fe80::1%lo0 at 2016-01-16 23:08:33 -0500
Started GET "/" for fe80::1%lo0 at 2016-01-16 23:08:43 -0500
I had a similar problem. Open your hosts file and see if there is a line like this:
sudo vi /etc/hosts
fe80::1%lo0 localhost
Commenting it out or removing should help.
By default running rails server will start in development mode. So I would expect a log folder to be created with further details:
gem install rails
rails new <name>
cd <name>
rails server
Than you should be able to view the error in the log
<project folder>
cd log
vi development.log

Spree - Timeout when trying to access backend

Since this afternoon, access to the backend of my spree shop is suddenly unavailable. When I try to visit any page in the backend (/admin/users, /admin/orders, etc) the page just loads for a long time, until it times out and I get the generic error page.
When I look into the logs I always see either :
Processing by Spree::Admin::OrdersController#index as HTML
Completed 500 Internal Server Error in 127259ms
** [Airbrake] Success: Net::HTTPOK
Errno::ETIMEDOUT (Connection timed out - connect(2)):
app/middleware/flash_session_cookie_middleware.rb:18:in `call'
or
Processing by Spree::Admin::OrdersController#index as HTML
Completed 500 Internal Server Error in 127520ms
** [Airbrake] Success: Net::HTTPOK
SocketError (getaddrinfo: Name or service not known):
app/middleware/flash_session_cookie_middleware.rb:17:in `call'
This started happening after the last deployment to production, which only changed images and stylesheets. I can't reproduce the error locally, despite having the same code and an exact copy of the production database.
I'm using Spree version 2.0.3
Run Spree::Config[:check_for_spree_alerts] = false in your console to fix this. You may also want to add this line to your initializers/spree.rb to ensure check_for_spree_alerts is not re-enabled in the future.
This is happening because the Spree Alerts website has been discontinued. See: https://github.com/spree/spree/pull/6516
To be specific, this is happening because when logging into the backend, Spree 2.0.x checks for any alerts from the Spree website here https://github.com/spree/spree/blob/2-0-stable/backend/app/controllers/spree/admin/base_controller.rb#L39 which then calls alert.rb:14 :
HTTParty.get('http://alerts.spreecommerce.com/alerts.json', query: params).parsed_response
At the moment, alerts.spreecommerce.com has been discontinued and is timing out, which explains the errors you're receiving.
The Spree Alerts code has been removed as of Spree 2.3, so you could also upgrade to that version to resolve this issue.

RoR - Not loading or requesting -any- assets in development mode

I'm brand new to Rails development and in a bit of a mess! I've been given a codebase and none of the assets aren't being referenced in the HTML. No failed network requests, they simply aren't being included in the mark-up! They are present there when I attempt to access them directly using their URL though.
As a comparison - my colleagues system ends up with around 30 or so requests and the end result is fully styled. However I have no styling and just the base mark-up.
I've done a fair amount of reading and checked my config, checked that I'm running in development mode and so on. I'm really stumped!
For what it's worth, I'm currently working in a cross-platform team environment where there are developers using Linux, Windows and Mac OS X. No one has these issues; and I'm pretty sure the other developer using Mac OS X has his set-up exactly the same as mine!
The source code was acquired from the same git repository as others, and it's definitely up to date. Below is the output from rails: note no errors.
=> Booting WEBrick
=> Rails 3.2.6 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
This poses a security threat. It is strongly recommended that you
provide a secret to prevent exploits that may be possible from crafted
cookies. This will not be supported in future versions of Rack, and
future versions will even invalidate your existing user cookies.
Called from: /******************/abstract_store.rb:28:in `initialize'.
[2013-04-17 21:20:55] INFO WEBrick 1.3.1
[2013-04-17 21:20:55] INFO ruby 2.0.0 (2013-02-24) [x86_64-darwin12.3.0]
[2013-04-17 21:20:55] INFO WEBrick::HTTPServer#start: pid=22421 port=3000
Started GET "/" for 127.0.0.1 at 2013-04-17 21:21:05 +0100
Processing by AccountsController#home as HTML
Completed 401 Unauthorized in 6ms
Started GET "/users/sign_in" for 127.0.0.1 at 2013-04-17 21:21:05 +0100
Processing by Devise::SessionsController#new as HTML
Rendered devise/shared/_links.erb (1.5ms)
Rendered devise/sessions/new.html.erb within layouts/application (10.0ms)
Rendered layouts/_navigation.html.erb (1.0ms)
Rendered layouts/_messages.html.erb (0.3ms)
Completed 200 OK in 776ms (Views: 86.5ms | ActiveRecord: 647.5ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-04-17 21:21:06 +0100
Served asset /application.js - 304 Not Modified (1ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-04-17 21:21:06 +0100
Served asset /application.css - 304 Not Modified (1ms)
Note: The application.js just appears to have 5 //=require directives; and the application.css has mainly comments with a few simple rules - nowhere near what should be there.
My solution is: install ruby version 1.9.3 and set this version as default. Restart your computer. Then install rails 3.2.6. Then clone a new repository for your source code (Do not reuse the one that is having error). Run bundle install.
Before this, I also tried to install ruby 1.9.2 with rvm but it does not work. Then I tried with ruby 1.9.3 and it works.
I've had a similar problem in a previous project. Personally I would try what everett1992 said because if that corrects the problem, it's probably best. But what I've used when that didn't work was the line
config.assets.prefix = "/assets_dev"
to my development.rb file.
Now, assets_dev is not a real directory, I never created it. But it forced rails to look there, and then when it doesn't see it, rails will load your assets from the default location as should happen in rails.
Like I said, it might work, but I'm sure its not the best way. I too work on OS X on cross platform projects with others, and I've yet to figure out why this sometimes happens.
I'm using mac os x 10.6.8 and I have the same problem, and tried all the solutions above. Nothing work.
Including:
1> update gem
2> remove rvm, reinstall rvm, ruby, rails...
3> and make configuration as config(dot)assets(dot)prefix = "/assets_dev"
By the way, I've checked GoogleChrome console, and realize that, within application(dot)css, there is still statement as below:
require_self
require_tree.
Which mean these reference does not works at all.
The same things happen to application(dot)js
P/S: I'm using rails 3.2.6

JQuery File Upload with Ruby on Rails/brackets

I was interested in JQuery File Uploader on Ruby on Rails and tried to use this applicationm and this one
I have made a new rails project with "rails new fily" and have copied and pasted all files in my fily-folder that they have in this application. I run bundle install and rake db:migrate but by opening localhost:3000/picture the only thing that I saw was: [], brackets and nothing more. What can be the reason?
In terminal I see following:
Started GET "/pictures" for 127.0.0.1 at 2012-10-21 23:21:13 +0200
Processing by PicturesController#index as HTML
Picture Load (0.2ms) SELECT "pictures".* FROM "pictures"
Completed 200 OK in 3ms (Views: 1.6ms | ActiveRecord: 0.2ms)
[2012-10-21 23:21:14] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
I would be grateful if somebody helps me
PS. I have found as well some very strange hidden file there:
.rvmrc
with a content:
rvm use ruby-1.9.3-p194#fily
What should that mean?
The .rvmrc file is used by RVM, the Ruby Version Manager, which allows multiple versions of Ruby to coexist on a machine, and allows you to specify which ones to use. The .rvmrc tells RVm to use the specified version of ruby, although it seems to me that the person who made that git repo used his own compiled from source. I don't think deleting it will bring any harm.
Looking at the code, (haven't got ruby on this machine yet so I can't test it to be sure), it seems as though you shouldn't be accessing /pictures. Instead, just access / (which calls and renders the pictures#new controller).

Spree error 500

Need some help here.
I have deployed spree (0.70.3) on slicehost (ubuntu, ruby1.8.7, Rails
3.1.3), installed the spree gem, loaded in the sample data
successfully following the steps on spree startup manual and I am
using passenger (it works on localhost:3000). When I upload to my
server, however, instead of seeing the spree interface, I am getting
an error message. From the production.log:
Processing by HomeController#index as HTML Completed 500 Internal
Server Error in 22ms ActiveRecord::StatementInvalid (Could not find
table 'product_groups'):
Any suggestions how I can get this to work?
Website: http://www.nutxboutique.com
production.log is the rails log. It appears your problem is occurring before rails completes loading. If you're using apache, check/post the apache logs, it might have more clues as to what's going on.

Resources