requirejs-rails icon indicating copy to clipboard operation
requirejs-rails copied to clipboard

undefined method `request_uri' for #<URI::Generic:0x000000081c95c8>

Open syrnick opened this issue 11 years ago • 10 comments

Getting this error when my baseUrl starts with "//" instead of "http://" or "https://".

syrnick avatar Mar 01 '13 01:03 syrnick

Note that there's no reason to set baseUrl unless you're using it for CDN hosting. That said, what do you hope to accomplish with a null URL protocol?

Next, please give a complete example of your baseUrl. It's fine to change names, etc., but you haven't given me enough information to determine if there's a real issue here, e.g. in what URI.parse returning vs. what the gem's code expects.

Last but not least, please provide the stack backtrace with issue reports.

jwhitley avatar Mar 09 '13 00:03 jwhitley

In https://github.com/jwhitley/requirejs-rails/blob/master/app/helpers/requirejs_helper.rb#L100

1.9.3p125 :008 > URI.parse('http://cdn.awsstuff.com').request_uri => "/" 1.9.3p125 :009 > URI.parse('https://cdn.awsstuff.com').request_uri => "/" 1.9.3p125 :010 > URI.parse('//cdn.awsstuff.com').request_uri NoMethodError: undefined method `request_uri' for #<URI::Generic:0x000001010484c0 URL://cdn.awsstuff.com> from (irb):10

I'd have to do more work to get the actual stacktraces and urls.

The use case is exactly that of serving assets from a CDN (cloudfront).

syrnick avatar Mar 09 '13 01:03 syrnick

Confirmed, thanks.

jwhitley avatar Mar 11 '13 20:03 jwhitley

Unfortunately, I am having the same error which is preventing me to release in staging/production:

Exception.message: undefined method `request_uri' for #<URI::Generic:0x007ffcb6257528>
Rails env: staging

Completed 500 Internal Server Error in 2459ms

ActionView::Template::Error (undefined method request_uri' for #<URI::Generic:0x007ffcb6257528>): 5: = stylesheet_link_tag "application", :media => "all" 6: %script{:src => 'http://connect.facebook.net/en_US/all.js'} 7: %script{:src => 'http://platform.twitter.com/widgets.js'} 8: = requirejs_include_tag "application" 9: 10: /[if lt IE 9] 11: %script{:src => "http://html5shim.googlecode.com/svn/trunk/html5.js", :type => "text/javascript"} app/views/layouts/application.html.haml:8:in_app_views_layouts_application_html_haml__2820337099112226929_70361663209760'

Rendered /Users/riteshn/.rvm/gems/ruby-1.9.3-p374@beamtous/gems/actionpack-3.2.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (5.4ms) Rendered /Users/riteshn/.rvm/gems/ruby-1.9.3-p374@beamtous/gems/actionpack-3.2.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.3ms) Rendered /Users/riteshn/.rvm/gems/ruby-1.9.3-p374@beamtous/gems/actionpack-3.2.2/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (27.4ms) ^[^[

...

In my config/environments/staging.rb:

config.requirejs.run_config['baseUrl'] = 'http://beamtous-staging-assets.s3.amazonaws.com/assets

psykidellic avatar Jun 17 '13 06:06 psykidellic

I'm running into this, too (setting config.requirejs.run_config['baseUrl'] in config/environments/staging.rb). Initially using //, now using https://, running into the error both ways: "undefined method `request_uri' for #URI::Generic:0x007f0b2a04e778".

daniel-nelson avatar Apr 16 '14 17:04 daniel-nelson

I think request.request_uri has been deprecated.

Now we can use:

request.url

ahmadhasankhan avatar Dec 15 '14 06:12 ahmadhasankhan

I'm encountering this issue as well. Any fix for it so i can dynamically choose between http or https? I am trying to hook my cloudfront CDN

AdnanTheExcellent avatar Apr 09 '15 17:04 AdnanTheExcellent

All, it looks like enough people have been asking for additional degrees of CDN URL customization. I'll try to look into this over the weekend and ping folks asking for clarifications and examples.

carsomyr avatar Apr 10 '15 04:04 carsomyr

Isn't it a Ruby stdlib issue? Is there any reason why URI::Generic does not have #request_uri?

irb(main):007:0> URI::Generic.class_eval do
irb(main):008:1*     def request_uri
irb(main):009:2>       return nil unless @path
irb(main):010:2>       if @path.start_with?(?/.freeze)
irb(main):011:3>         @query ? "#@path?#@query" : @path.dup
irb(main):012:3>       else
irb(main):013:3*         @query ? "/#@path?#@query" : "/#@path"
irb(main):014:3>       end
irb(main):015:2>     end
irb(main):016:1> end
=> :request_uri
irb(main):017:0> URI::HTTP.superclass
=> URI::Generic
irb(main):018:0> URI.parse('//cdn.awsstuff.com').request_uri
=> "/"

Nakilon avatar May 07 '18 07:05 Nakilon

I think the main reason is that request_uri looks for 'http://' or 'https://' as shown here.

So in order to use request_uri, one must imply the underlying protocol.

As of Rails 3.1, use '.url' instead. As shown here

cjdeclaro avatar Oct 28 '19 06:10 cjdeclaro