Rails Redirect Route Bad Host Component - ruby-on-rails

So I'm trying to make a redirect in my routes.rb. I'm getting an error when I leave off my domain.
match "/partners/" => redirect("/partners.html")
Navigating to /partners/ gives this error page:
URI::InvalidComponentError
bad component(expected host component): frontend_rails.dev
However, it does work if I put our full domain in the redirect.
match "/partners/" => redirect("http://example.com/partners.html")
But for my dev server I don't like links to go to our production server. According to the rails doc, this should be added automatically:
In all of these cases, if you don’t provide the leading host (http://www.example.com), Rails will take those details from the current request.
Any ideas why it's not liking my relative redirects? Thanks!

Almost a year later and I finally realized what the problem was. It actually WAS a bad URI. The repo in GitHub was called frontend_rails. I used the Pow server, which gives you a host based on your folder name (which, when you check out a project defaults to the name of the GitHub repo), so http://frontend_rails.dev.
However, underscores technically aren't allowed in a URI. This was tripping up the URI gem. I symlinked my project frontend_rails to frontend-rails and now it works. Voilà !

Related

Using Go Daddy domain with Gitlab pages is causing my resources to be referenced with the wrong path

I've configured the DNS for my Go Daddy domain to link to a gitlab pages URL the resources seem to be looked for at a path using the project name, which I am struggling to understand because the same thing works when using the gitlab URL:
Application using gitlab URL:
Application using domain name:
in the second image if you remove the /mythosgames/ path the files are located there which is honestly what i would expect, and i would have thought that:
https://glentopherlamb.gitlab.io/mythosgames/ = https://glentophergames.co.uk/
So I am kind of confused why that path works for the gitlab link, i would expect both to be wrong, can anyone point me in the right direction as to how to fix this. I fear i am in a little over my head.
Navigate to https://glentophergames.co.uk/, open the browser dev tools, switch to "network", refresh the page - and you'll see that there are some requests with error response codes.
This is because you have specified the publicPath (with the value "mythosgames"), so now when the index is loaded, it's trying to load all the resources from the /mythosgames/ base path - which is incorrect when loading the page on your own domain, because in that case they should be loaded from the root (/) base path (no subfolder).
You can "fix" this by setting the publicPath value to ./, so all assets are loaded relatively to the index.html file (or better said, relative to current path).
Keep in mind that this can break apps with client-side routing using "legacy" (non hash) navigation.

Is it possible to share my localhost with someone on a different network?

I am working with a designer and I'd like them to have access to the interactions I've implemented on the site we're working on. However this time, I have 2 issues. My localhost is configured to a subdomain:
http://store.teststore:3000/ and we're on different networks. Is there anyway to work around this?
ngrok should work for you. Download and install it following these instructions here: https://ngrok.com/download. Documentation on how it is used can be found here https://ngrok.com/docs. Once installed running the below command should work for you (depending on the hosting environment):
ngrok http -host-header=rewrite store.teststore:3000
You will need to give the URL generated by ngrok and displayed in the cmd prompt to the designer.
Update: Handling absolute redirects
Based on your comment it sounds like, after login, your site does an absolute redirect (the full URL is specified). If it is possible I would change your code to do a relative redirect where the domain is omitted. You could also make your root domain configurable in the absolute redirect and configure it to be the ngrok domain provided for now. Lastly, you could attempt to configure your DNS with a CNAME record following ngroks Tunnels to custom domains documentation. This last option, however, requires a paid for ngrok subscription.
Install ngrok if you haven't yet and CD into your project directory and invoke ngrok. Note Your application must be running locally on the same port number ngrok will be running.

Tricky redirect/rewrite

I searched for this one, but found nothing ...
My old site is: cs.abc.edu/~cs4096
My files were at: cs4096#cs.abc.edu/public_html
My personal site: myname.com
My Github Pages site: myname.github.io
When a user requests cs.abc.edu/~cs4096 they are served cs.abc.edu/~cs4096/index.html and so on.
Via the ISP hosting myname.com, I setup a CNAME pointing teaching.myname.com to myname.github.io .
I want references to the old site, including pages below the top index.html, to be sent to teaching.myname.com where through the magic of DNS CNAME the URL goes to the myname.github.io site. In other words, users still go to the cs.abc.edu/~cs4096 but they are served from github.io.
The teaching.myname.com -> myname.github.io bit is working fine. It’s the initial redirect/rewrite that is failing. The problem is that the ~cs4096 is included in the URL when it is passed to myname.com .
That is, this
http://cs.abc.edu/~cs4096
ends up as
http://teaching.myname.com/index.html~cs4096
instead of
http://teaching.myname.com/index.html
and this
http://cs.abc.edu/~cs4096/Schedule
ends up as
http://teaching.myname.com/index.html~cs4096/Schedule
instead of
http://teaching.myname.com/Schedule
And, if you wonder WHY I’m doing two “redirects” here, it is because want the automatic rebuild of github pages that I can’t get at abc.edu or myname.com .
Thank you all
Never mind ... I abandoned this idea and used an HTML Redirect. It will mess up “Back” in the Browser, but it works.

Running graphgists locally fails

I'm interested in running a graphgist locally, for which there is a script here:
https://gist.github.com/jexp/70296ce410ff431ddbef
I was able to install the modules and run the two tasks but the last line of the script:
open http://localhost:8000/?http%3A%2F%2Flocalhost%3A8000%2Fgists%2Fmy-graph-use-case.adoc
produces an error: Not Found and trying to open the link in the comments:
http://localhost:8000/gists/my-graph-use-case.adoc
causes my browser to download a file for which I have no associated application. has anyone made this work and if so, how?
according to #MichaelHunger the issue is that the default behaviour in Python's SimpleHTTPServer is such that a trailing slash (/) gets added to the end of the url, messing up the request.
according to #PratikMandrekar, in the following article, the problem is that the url as it is in the script does not explicitly specify the file name, forcing the server to redirect to the default. see:
Why does SimpleHTTPServer redirect to ?querystring/ when I request ?querystring?
so after a little experimentation I found this to work:
http://localhost:8000/index.html?http%3A%2F%2Flocalhost%3A8000%2Fgists%2Fmy-graph-use-case.adoc
notice that the colons, slashes, etc. in the inner url must be encoded for this to work
There is a bug/default behavior in simple-http-client that makes it add slashes after query parameters which breaks our app in this case, I have to find a better replacement or fix it.
Perhaps I can also change the rabbithole project to server the graphgist files itself, so that it would be self-contained.

Symfony 1.4 Backend app for admin fail on Prod environment

I have a perfectly working admin backend on my dev environment but it fails miserably on the prod environment. Specifically a bunch of problems arise :
It is unable to read the symfony/web/sf/ directory hence not loading the required images though it states that a project has been successfully created. This however is not the case with the frontend leading me to believe that the problem is more sinister than what meets the eye.
Though it loads the admin pages, the css is not loaded, even though admin.css is present in the web/css directory.
I did an inspect element and the problem seems to be this, instead of routing to
/web/css or /sfDoctrinePlugin or /web/js
it prefixes the name of the app [controlcenter in my case] to everything, essentially rendering the HTML as:
href = "/controlcenter/web/css" or href = "/controlcenter/js" or href = "/controlcenter/js" . And this does not happen at all on my dev environment and things render the way they do.
Fixits anyone?
This was completely ridiculous of me to post this. I was simply trying to go to controlcenter/module which basically translates to backend/module for most people.
The index file in this case is controlcenter.php, and upon accessing that, I get the website to render the way it ought to. Sorry for the confusion people. Hopefully someone drops in by and sees the answer for themselves.
I should set up defaults in my routing.yml so that it automatically redirects without me having to type controlcenter.php
Thanks

Resources