Heroku mongo_mapper MONGOHQ_URL unparseable by ruby uri - ruby-on-rails-3

I have scoured the Internet without finding an adequate solution, so I'm here to ask the SO community for help.
I'm migrating a rails 2 app on Heroku Bamboo to Cedar. Concomitantly, I am moving to rails 3 and ruby 2.0.0 (though I get this error with ruby 1.9.3 as well).
It seems that MongoMapper has undergone a bit a change from 0.8.6, to the point where I can't use our old initializer anymore. I'm attempting to use the latest 0.13.1 version of mongo_mapper.
According to https://devcenter.heroku.com/articles/mongohq, I just need to set config/mongo.yml to:
production:
uri: <%= ENV['MONGOHQ_URL'] %>
and I'm all set (I also commented out the old initializer code). However, it fails with the following connection error:
Feb 05 11:18:28 my-app-name app/web.1: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/uri/generic.rb:214:in `initialize': the scheme mongodb does not accept registry part: heroku:2QMdYzo6z5nmJJsmWAWKd_205umc05tBuP2ZodGaNDZ7N5rE4ns09jhsfFBjmkQ2ls_rfTiVC0lD24Y2byDXbg#candidate.21.mongolayer.com:10499,candidate.4.mongolayer.com:10625 (or bad hostname?) (URI::InvalidURIError)
An invalid URI is understandable, but that's what being fed to me by Heroku. What do I am missing in order to for the uri parser to accept it?
Thank you in advance.

The answer lies in the presence of that comma (,) in the uri. When I removed the second host and the comma, it behaved correctly :-)
Specifically, I created a Heroku ENV variable called MONGOHQ_URL2 without the second host name, then updated my config/mongo.yml to use that one instead.

Related

A custom route is matched in development but results in 404, in production

I have a following definition in my routes.rb
match "/block/:name/:action" => proc { |env|
#heavy magic happens here
}
I use it for handling rendering of cells. My problem is that the following link:
/block/reporting%2Fother%2Fexample/new?exampleable_id=23736&exampleable_type=Abc%3A%3ASomeType
works perfectly fine in development mode, but in production I get "404 Not Found". The only difference between production and development urls is that the one in development uses http and the one in production uses https. I would understand if I wrote a faulty code my proc block, but for the love of god I can't understand why it is not matched in production environment, when it works perfectly fine in development.
Any hint on how to debug this is highly appreciated. There is not so much hair left on my head.
I got this error even when if I finally launched the project in production environment on my local machine. The thing is we do not use Thin in production. We use passenger. After I finally got passenger working locally, I managed to recreate the error.
It turned out that with passenger, the :name in aforementioned route wasn't interpreted as "reporting%2Fother%2Fexample", but possibly as /block/reporting/other/example/new" with the rest not matched, of course.
I fixed the error by replacing
match "/block/:name/:action"
to
match "/block/*name/:action"
I hope this answer to my own question helps someone in the future.

Heroku is driving me nuts! Is my code amazingly sloppy, or is Heroku amazingly picky?

wow. going super nuts here trying to deploy to staging on heroku cedar from Rails 3.2.2. I've gotten everything to work, but I wanted to run these issues up the flagpole to see if there's something wrong with... me. eheh
Both of these issues give me the not-helpful "We're sorry, but something went wrong." error page. So it was frustrating when I had 2 different issues (that acted like 3) in one deploy (that worked fine on my local).
Heroku won't give me my logs.
when I run
heroku logs
I get a long error message that starts with,
c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:762:in `initialize': Permission denied - connect(2) (Errno::EACCES)
so i've been doing all this troubleshooting via small slices of commits. maddening.
Heroku chokes when it can't find an image with image_tag
this works on heroku:
= image_tag("content/portfolio/maskphoto_rubble_rebel_blur.jpg", :alt => params[:photo], :width => "100%")
This doesn't (only difference is an extra letter in the file name, though it works on my local):
= image_tag("content/portfolio/maskphoto_rubble_rebell_blur.jpg", :alt => params[:photo], :width => "100%")
Am i nuts in thinking that heroku should just serve up the image tag as-is and let it just not display, rather than crashing the entire page? I'm running compass; not sure if that has anything to do with anything.
Heroku hates nested expressions in an array ref
this works:
n = f.index(params[:photo]) +1
#nextphoto = f[ n ]
this doesn't (but does on my local):
#nextphoto = f[ f.index(params[:photo]) +1 ]
i guess it's better form to separate expressions, but still. why would it work on my local and not on deploy?
I can't directly answer all of your questions, but here are a few things to look at:
Heroku won't give me my logs.
The error you are getting indicates Permission denied ... Perhaps your account credentials are not setup properly? I see you are on a windows box ... on a unix machine, the heroku client writes a file at ~/.heroku/credentials with the username and what appears to be an API token. Check to see if you have a similar file. You can also check https://toolbelt.herokuapp.com/windows and make sure you have successfully performed the heroku login command.
Heroku chokes when it can't find an image with image_tag
I don't have many ideas here. Perhaps it is related to the asset-pipeline?
Heroku hates nested expressions in an array ref
This one doesn't make a whole lot of sense either. Perhaps the logs can shed some light here. I did notice that you appear to be running Ruby 1.9.3 on your system, and I don't believe heroku supports 1.9.3 yet. Maybe you have hit a version-specific bug.
I hope that helps. Good luck.

Deploying rails 3.1 app in subdirectory

I'm trying to deploy my rails 3.1.3 app in a subdirectory on the server:
Apache (reverse proxy) => unicorn (listening on localhost:5000)
The problem is with url_helper.
via the --path switch in unicorn I'm setting my /subdir
It gets picked up by rails; DashboardController.config.relative_url_root gives me that subdir.
But when I use something like 'members_path' in my view it gives me '/members' and not '/subdir/members'
what am I missing?
I had exactly the same problem. Two things were missing/faulty in my setup.
My web-server had an superflous, faiulty rewrite-rule, rewriting /prefix/<controller> to just /controller.
It seems Rails3 routing are by default ignoring relative_url_root. (Stupid IMHO) There's a good tip in https://stackoverflow.com/a/5457484/103192 that shows a trick to make it work again.
Otherwise, you can wrap the run statement in your config.ru with the
following block:
map ActionController::Base.config.relative_url_root || "/" do
run FooApp::Application
end
I now have it working much like one would want it to work.

Routing error: wrong constant name Clearance/sessionsController

I've upgraded a rails3 project from clearance 0.8.8 to the latest (0.12.0). followed the wiki instructions to do that.
I'm using an 'admin' prefix to most of the authenticated pages. However, eventhough the routes are all correct, I get a routing error when I try accessing 'session/new'.
I'm overriding the session/new view to apply a specific layout.
Any idea what might be causing of the error?
Here is the output from the logs:
Started GET "/sign_in" for 127.0.0.1 at Wed Oct 05 17:34:05 +0300 2011
ActionController::RoutingError (wrong constant name Clearance/sessionsController)
The routing error turned out to be a conflicting String#camelize with right_aws gem v2.0.0
All you need to do to get clearance working in this case is update right_aws gem
PS: found the answer here (devise routing error)

URI::InvalidURIError (bad URI(is not URI?): ):

I am trying to implement an OAuth provider in Rails 3. When I try to authorize a client app I get this error. I am using the RESTful auth plugin and pelles OAuth-plugin. When I was testing via the Rails console and getting this error I thought that I simply needed to encode the URLs but I get the same error when testing in browser so I am not sure what is wrong.
I got into trouble with URI.split (returning this error), I don't know if this helps you, but I will post here some warnings for also someone else having this error:
Check your url is not nil, and it's a valid one.
Do URI.encode(url) before URI.parse (to avoid special characters)
Do strip to the string you pass to URI.parse (to avoid leading and trailing whitespaces).
All in one:
uri = URI.parse(URI.encode(url.strip))
Related resource: http://www.practicalguile.com/2007/09/15/raising-uriinvalidurierror-from-a-perfectly-valid-uri/
You can also use this alternative URI gem: https://github.com/sporkmonger/addressable
There is no such problems with it.
Very native, just add namespace in your code after installing the gem
Addressable::URI
try this:
safeurl = URI.encode(url.strip)
response = RestClient.get(safeurl)
I'm here because I faced an issue with the fastlane. It's been written with Ruby thus my answer can be helpful.
In my case, I had the environment variables http_proxy = XX.XX.XX.XX:XXXX and https_proxy = ...
When I changed them to http_proxy = http://XX.XX.XX.XX:XXXX and https_proxy = https://... respectivle the issue has gone.