Rails 3 can't find route to static page - ruby-on-rails

Am working my way thru Ruby on Rails Tutorial: Learn Rails by Example. I'm in the section entitled Mostly Static Pages.
I get an error after I create an HTML page in the public directory which is called public/hello.html and should appear as in Figure 3.3. My problem is that when I try to create the page and make it appear at localhost:3000/hello.html I don't see the rendered page. Instead, I get an error which says "Routing error No route matches "/ hello.html"
I have not made any changes to the routing; I thought that Rails was supposed to be smart enough to find "hello.html" because it's in the same directory as the "public/index.html" page and the name of the page is "hello.html"?
Can you please explain?

If you're like me and powering through the book, I left the server running from the prior chapter, so it was still loading index.html from the demo_app directory.

You're following an old guide. A newer version
http://ruby.railstutorial.org/chapters/static-pages#sec:green
tells you that you need to modify the routes.rb in the config folder.
I spent about an hour crying about this.

Are you sure you typed this correctly? It looks like you've typed "localhost:3000/[space]hello.html" rather than "localhost:3000/hello.html". Please double check.

Move the file to the Public folder. That did the trick for me.
The hint I used is that Rails serves the Public folder by default. So I figured, if I put it in the Public folder, that ought to work. You'll see it's in line with the index file, so I think that's proof, too.

Review your app directory again and make sure you save the file in (my case) :
C:\Users\Nnamdi\rails_projects\sample_app\public\hello.html
I had the same issue but realized that I did not save it in the right directory
..The solution above should work..cheers

Related

Change domain without 404 error code?

I have changed all the URLs of my website. (Domain is the same. For example: http://www.example.com/category/sample ----> http://www.example.com/Category/Sample)
Now it seems to have lots of 404 pages that are effecting my SEO.
What should I do to solve this problem? Any suggestion?
Thank you
You can proceed with changing the Context root for your website. Context roots determine the URL of any web-application.
Click here for a short article for making changes to context-roots.
The process may change based on the Server you are using.
Just create sitemap.xml file. There are many online sites available that will create free sitemap.xml file. Just you have to submit your website url and within few seconds they will generate sitemap.xml file. Download this sitemap.xml file and place it into your root directory. When crawler run through your website it will automatically update your all links and within few days you will see all updated links are present in search resulting page like google search engine.
Note: Also, dont forget to update sitemap.xml file path in robot.txt file.

Show bundle render options when coding (Style.Render-Script.render)

So I’m starting with mvc and I find hard to remember the name of my bundles. When using visual studio it seems easier to just drag and drop the script I need instead of going to my app_start folder and check the name of my bundle.
Am I doing something wrong? Is there any way to show my bundles when I write Styles.Render.
I’m using reshaper too but no option is showed.
Here is an example.
Seems easier to drag and drop my script/style:
Than writing #styles.render() because it won’t show my bundles so I have to go to my app_start folder and copy-paste it (What I actually do).
If there is an easier way please let me know.
Thanks
Normally you'd create a _layout.cs that imports the styles for most pages, that solves most of your issues, since you only have to do it once. Then what I normally do is create a bundle config for a specific page that has the same name as the controller or view (easy to remember) which has the page specific styles and scripts. The Bundle Config is where I set this up. Resharper (8.1) does help me when selecting paths from my bundle configuration.

Html file avaliable from request

I need to confirm ownership of domain, as instruction says, place special .html file in main directory.
It confused me. Tutorial says, that file should be avaliable as www.domain.com/file.html
I placed it in views folder, but nothing. I wouldn't like to set special controller-action-route for that(it is quite weird), but looks like I should? Or other way?
How do I do that in terms of Rails app?
Just put file.html under the public folder, and visit www.domain.com/file.html
In Rails everything within the public folder is visible to the outside world.

Using resources for localization in MVC4

I'm following this tutorial that was given as answer in this question, however I'm stuck at displaying the resource.
Just like in tutorial I've created two files
App_GlobalResources
/Global.en.resx
/Global.ru.resx
I've made data annotation class that works and adds a cookie with no errors, it means it injects the local data into current thread properly. When I try to output resource it cannot find it.
I've tried to output it like this and none of these works:
#Global.HomeHello
#Global.en.HomeHello
#Resources.Global.Homhello
// The name 'Resources/Global/etc...' does not exist in the current context
Also, in this tutorial site I see no logic that will inject the proper resource file, how it can do something like (in tutorial) #Global.HomeHello and it will know that if url is /en/ he needs to use Global.en.resx
Please help, first time using resources and implementing multiple languages, feels 100 times more harder and confusing than using *.yml files in other frameworks/languages...
You took a bad example to follow I guess. Please look into the following article:
Resource Files and ASP.NET MVC Projects
Don't forget to change Custom Tool to PublicResXFileCodeGenerator and Custom Tool Namespace to Resources.
Hope this helps & good luck.

sitemap localization not working

Strange things happening. If I have only one file filename.en-US.resx file in App_GlobalResources. Sitemap(Which is referring as "$resources:Web.sitemap,key") is throwing error that object or key couldnt find. But when i have two files filename.en-US.resx and filename.resx[this has no keys it is empty], sitemap is working fine. Please need some explanation.
I think you need to have a filename.resx that acts as the normal (invariant) resource before adding culture/language specific resource files.

Resources