Rails route rewriting - ruby-on-rails

I think this is an easy question. I am using this useful Flash Document Reader called FlexPaper. I have it embedded in one of my Show pages. But when I click the a link on their tool bar to show the document in a new browser, it points to the following link:
http://example.com/intels/FlexPaperViewer.swf?ZoomTime=0.5&FitPageOnLoad=false&PrintEnabled=false&SwfFile=%2FPaper.swf
which doesn't work, I get the following error:
ActiveRecord::RecordNotFound in IntelsController#show
Couldn't find Intel with ID=FlexPaperViewer
but if I remove the "intels" from the path so the url looks like:
http://example.com/FlexPaperViewer.swf?ZoomTime=0.5&FitPageOnLoad=false&PrintEnabled=false&SwfFile=%2FPaper.swf
It works fine.
My question is what is the best way to handle this? Can you write a route that rewrites a url that starts with intels/FlexPaperViewer.swf and remove the intels prefix? What would that look like?
Is there a better option?

Juat a thought, how about placing the FlexPaperViewer.swf inside public/intels folder?
So the directory structure will be
<project-directory>/public/intels/FlexPaperViewer.swf
Doing this will make the link correct. It seems to be easier to do it this way.
Hopefully it helps.
EDIT
Another alternative will be to see how the link was generated, maybe there is a parameter that you can set when you embed the FlexPaper.
I am not aware of any route modification that can do what you want. Maybe someone else can help on this.

Related

Missing the middle or a URL

I was wondering if there was a way to find a URL when I am missing the middle. For example, I know that the beginning will be https://welldressedwolf/products/
and the end will be pretty-things but I do not know the middle portion.
With javascript you can get the full URL using window.location.href
After that you can remove the parts you dont want and you will have the middle.
More info: https://www.w3schools.com/js/js_window_location.asp
If you're looking to manually look up the address of a page, you could do so with a google search that specifies the site.
Try a site specific google search using something like the following:
"pretty things" site:welldressedwolf.com

Remove /sitecore from the URLs

I need to remove "/sitecore" from URLs because when I navigate to appropriate sites (www.site_name/sitecore) I will get empty page with no layout. I would like to ask you
1) Is good option to use redirect to solve my problem ?
2) Can this redirection of the "/sitecore" caused problems ? I found that in sites definition of my web config I have a lot of site definition like this:
site name="shell" virtualFolder="/sitecore/shell" physicalFolder="/sitecore/shell ... where "/sitecore" is part of some other paths so I am not sure.
I appreciate your help. Thx

Get url of Orchard default pages

I am using orchard 1.9 and I am building a service in which I need to get current URL.
I have OrchardServices and from that I can get the URL like so:
_orchardServices.WorkContext.HttpContext.Request.Url.AbsolutePath;
This works like a charm for pages/routes that I have created but when I go to the Login or register page (/Users/Account/LogOn) the absolute URL is / and I can't find anyway to get the URL or at least any indication that I am in the LogOn or Register.
Anyone knows how I could get the full url?
If I understand what your're asking, you could use the ItemAdminLink from the ContentItemExtension class.
You will need to add references to Orchard.ContentManagement, Orchard.Mvc.Html and Orchard.Utility.Extensions, but then you will have access to the #Html and #Url helpers.
From there you will have the ability to get the link to the item using:
#Html.ItemDisplayLink((ContentItem)Model.ContentItem)
The link to the item with the Url as the title using: #Url.ItemDisplayUrl((ContentItem)Model.ContentItem)
And you should get the same for the admin area by using these:
#Html.ItemAdminLink((ContentItem)Model.ContentItem)
#Url.ItemAdminUrl((ContentItem)Model.ContentItem)
They will give you relative paths, e.g. '/blog/blog-post-1', but it sounds like you've already got a partial solution for that sorted, so it would be a matter of combining the two.
Although I'm sure there are (much) better ways of doing it, you could get the absolute URL using:
String.Format("{0}{1}", WorkContext.CurrentSite.BaseUrl, yourRelativeURL);
...but if anyone has a more elegent way of doing it then post a comment below.
Hope that helps someone.

acts_as_taggable_on url friendly tag names

Is there a way to make the tag name on acts_as_taggable_on to be URL friendly?
For example, at the moment I have 'tags/foo' and 'tags/bar' working great. However when I add spaces to the name such as 'rabbits foot' the url is 'tags/rabbits%20foot'. I'd like to replace that %20 with a dash.
Thanks in advance!
UPDATE
I just noticed that stackoverflow actually uses a very similar or identical way of doing tags to what I have in mind.
Take a look at this
https://github.com/arturaz/acts_as_taggable_on_steroids
It has a way to change the multiple words into a slug (e.g. rabbits foot into rabbits-foot), there's also manual non plugin ways to do this as well (it looks somewhat outdated).
Decided to kind of cheat and use the id+tag.name just to get passed this hump for now. Will revisit when I have more time.

dynamic seo title for news articles

I have a news section where the pages resolve to urls like
newsArticle.php?id=210
What I would like to do is use the title from the database to create seo friendly titles like
newsArticle/joe-goes-to-town
Any ideas how I can achieve this?
Thanks,
R.
I suggest you actually include the ID in the URL, before the title part, and ignore the title itself when routing. So your URL might become
/news/210/joe-goes-to-town
That's exactly what Stack Overflow does, and it works well. It means that the title can change without links breaking.
Obviously the exact details will depend on what platform you're using - you haven't specified - but the basic steps will be:
When generating a link, take the article title and convert it into something URL-friendly; you probably want to remove all punctuation, and you should consider accented characters etc. Bear in mind that the title won't need to be unique, because you've got the ID as well
When handling a request to anything starting with /news, take the next part of the path, parse it as an integer and load the appropriate article.
Assuming you are using PHP and can alter your source code (this is quite mandatory to get the article's title), I'd do the following:
First, you'll need to have a function (or maybe a method in an object-oriented architecture) to generate the URLs for you in your code. You'd supply the function with the article object or the article ID and it returns the friendly URL with the ID and the friendly title.
Basically function url(Article $article) => URL.
You will also need some URL rewriting rules to remove the PHP script from the URL. For Apache, refer to the mod_rewrite documentation for details (RewriteEngine, RewriteRule, RewriteCond).

Resources