jwhitley / requirejs-rails

RequireJS support for your Rails 3 or 4 application
MIT License
592 stars 202 forks source link

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

Open syrnick opened 11 years ago

syrnick commented 11 years ago

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

jwhitley commented 11 years ago

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.

syrnick commented 11 years ago

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).

jwhitley commented 11 years ago

Confirmed, thanks.

psykidellic commented 11 years ago

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

daniel-nelson commented 10 years ago

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".

ahmadhasankhan commented 9 years ago

I think request.request_uri has been deprecated.

Now we can use:

request.url

AdnanTheExcellent commented 9 years ago

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

carsomyr commented 9 years ago

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.

Nakilon commented 6 years ago

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
=> "/"
cjdeclaro commented 4 years ago

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