0

I am learning Ruby on rails and wanted to import my git repo to Cloud9 to continue working over there.

https://github.com/christoph88/sample_app

I imported it. Did a bundle install, rake db:migrate, rake test:prepare and everything seemed to work fine.

Until I try to register or login. Then I get following error. I read somewhere it has to do with the routes but I do not understand.

Can somebody help me locate the problem? (and explain it to me) Thanks!

 SQL (0.4ms)  UPDATE "users" SET "remember_token" = ?, "updated_at" = ? WHERE "users"."id" = 1  [["remember_token", "92add7938701a70880243cf9ca88338d37b1a0ae"], ["updated_at", Fri, 29 Aug 2014 10:21:28 UTC +00:00]]
   (13.2ms)  commit transaction
Redirected to https://sample_app-c9-christoph88.c9.io/users/1
Completed 302 Found in 88ms (ActiveRecord: 13.9ms)
[2014-08-29 10:21:28] ERROR URI::InvalidURIError: the scheme https does not accept registry part: sample_app-c9-christoph88.c9.io (or bad hostname?)
        /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/uri/generic.rb:1203:in `rescue in merge'
        /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/uri/generic.rb:1200:in `merge'
        /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpresponse.rb:276:in `setup_header'
        /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpresponse.rb:206:in `send_response'
        /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:110:in `run'
        /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Christoph
  • 1,347
  • 2
  • 19
  • 36
  • 1
    This is because you have `underscores` in your `URL`. RFC URLs can contain only letters and numbers. So you are getting this error. For workaround, refer this answer : http://stackoverflow.com/a/5209551/1115353 – Bharath Mg Aug 29 '14 at 10:32
  • @BharathMg Thanks for your help but where do I need to put this code? How does it work? Thanks! – Christoph Aug 29 '14 at 11:32

2 Answers2

0

Does Cloud9 allow you to change the name of your app from "sample_app" to "sample-app" (i.e., replace the underscore with a hyphen)? That's probably the least complex solution here.

If you can't change the name of the app, @Bharath Mg's link to the other Stack Overflow thread is helpful (here it is again: Is there a workaround to open URLs containing underscores in Ruby?). The accepted answer in that thread catches your InvalidURIError thrown by the open-uri library and makes another attempt using the net/http library.

EDIT: The other Stack Overflow post is really only useful in that the questioner in that post notes that the error only occurs when an underscore is present in the name of a sub-domain, and the accepted answer appears to identify the problem: "a bug in URI, and uri-open, HTTParty and many other gems make use of URI.parse." The questioner in this post is using Rails, as opposed to plain Ruby, and thus cannot easily implement the accepted answer.

Community
  • 1
  • 1
Travis Hohl
  • 2,176
  • 2
  • 14
  • 15
  • I added the rename gem to my gemfile using this tutorial. http://stackoverflow.com/questions/20988813/how-to-rename-rails-4-app This creates a new renamed folder but the error stays the same. Where do I put the code from the solution @Bharath Mg's link. Is it a helper or how does it work? – Christoph Aug 29 '14 at 14:15
  • To be clear, you've successfully changed the name of your Rails app from "sample_app" to "sample-app" but you are receiving _exactly_ the same error that you provided in your question above? – Travis Hohl Aug 29 '14 at 14:23
  • I added this "gem 'rename'" to my gemfile. Then ran "rails g rename:app_to Sample-Application". This created a new folder in my home directory.(sample application). so no underscores used. Started the server again and tried to log in and received the same error. If this is impossible I'll try it again when at home. It could be that I needed to refresh the page first or something like that? If not where should I put above could or could you give me a hint so I can Google further. – Christoph Aug 29 '14 at 14:40
  • It'll be simpler to make sure the app is being renamed properly and that you're running the newly renamed app instead of the previous app by mistake. The questioner in http://stackoverflow.com/questions/5208851/is-there-a-workaround-to-open-urls-containing-underscores-in-ruby/5209551#5209551 was using plain Ruby and the "open-uri" gem. However, you're using Rails -- which means it may be more complicated to try and work around Rails' use of URI.parse. – Travis Hohl Aug 29 '14 at 15:51
  • thanks, now I understand. I'll fiddle with it and let you know how it goes. – Christoph Aug 29 '14 at 16:16
0

I got it working by renaming the app using the 'rename' gem. The new name should not contain an underscore. After that I pushed the renamed folder to a new repository in github. Reloaded that new repository in a new Cloud9 project file. Rebuild everything and got it back working.

Once the Cloud9 project file exists the url keeps the app name. The only way to change that url is to create a new project.

Christoph
  • 1,347
  • 2
  • 19
  • 36