I just figured out how to create custom error pages in the public folder using I18n. Those error pages have links that will return the user to a page in the application such as the home page.
When my application was running 3.2.13 I had the custom error pages in the app folder using config.exceptions_app = self.routes in application.rb. When I had that code all I had to do was use a link_to statement pointing to the route I wanted the user to return to. If I was in the development environment it would go to http://localhost:3000/somelink and in production it would go to http://myrailsapp.com/somelink. I replaced these with the ones in the public folder after rewriting them in Rails 4 because it appears that config.exceptions_app = self.routes is ignored in Rails 4.
My error pages in the public folder are html, not html.erb so there is no ruby/rails code. I would like to replicate what I had previously where I can check the environment in my error pages and point to localhost for development or my domain URL for production. I currently have code in my error page similar to this:
My Link Text
I'm definitely open to changing these to html.erb files. I initially thought about that but from my research and trying what I found nothing is working for Rails 4.
Any help would be appreciated.
You don't need any "autodetection" in html, just cut the domain part from the url and use a local path instead.
Just change http://myrailsapp.com/en/home to /en/home.
And yes, you do need the opening slash to be independent from the current_url in your link.
Related
I was developing this rails app that has mostly static pages. I downloaded a template from bootstrapicious and created a pages controller to hold all my static pages, changed the file names to have a .html.erb extension and the routes. Everything was working out fine in the index page; all images, css and js were working fine. But other pages aren't loading the animate js and images. I created a link of the home pages without using root_path and it behaved the same. I'm stranded and don't know what to do. Please help. quite a newbie in rails.
Stop the Rails server and try this command
rake assets:precompile
After this re-start your rails server!! Let me know if this what you wanted.
I am using Ruby on Rails 4.1.1 and I want to add a linked image - my app's logo - in email messages but I had a doubt since my previous question.
By using files located in the public directory it seems that to link to an image in your Asset Pipeline you can use
link_to(LINK_TEXT_OR_IMAGE_TAG_HELPER, image_path(IMAGE_NAME))
but for those located in the app/assets it seems do not work the same, at least in rendered email messages in production mode. All assets that are compiled in Production have a fingerprint ID... is the fingerprint causing the load of static assets to do not render images in email messages?
I doubt since I would like to access images from both browser and email. I tried to solve the issue by moving the image from app/assets/images/logo.png to public/images/logo.png and by changing statements in my application.css.scss file from image-url("logo.png") to url("/images/logos.png"). However I do not know if I am following "the Rails way" or a "best practice". Do I? Should I add to the public directory all assets that I plan to use outside my application and in the app/assets directory all assets that I plan to use internally to my application?
For emails, it almostisn't any different compared to standard Rails views.
You can link to an image in your mailer using the image_tag helper you'd normally use in regular views as well:
<%= image_tag('some_image.jpg') %>
You also need to tell Action Mailer where it can find the assets, because it will use absolute URLs to refer to your images:
config.action_mailer.asset_host = 'http://www.example.com/'
I need the public facing url of an image in my app/assets/images directory.
On development, I can navigate to the image by hitting localhost:3000/assets/image.jpg.
However, when I push this app to heroku, that url no longer works.
I can't visit my_app.com/assets/image.jpg or I get a routing error saying "No route matches get assets/image.jpg."
How can I navigate to that URL? I am not really interested in helper methods to generate the URL, I just need the full length url.
Are you including the rails_12factor gem in production? This will do a number of things for you, including set config.serve_static_assets to true which is false by default in production.
I'm making a blog system for my Rails application and I'm stuck with this problem a while and don't know what's going on with my routes.
I installed a template for my app and all the css/js/images files from this template are in "public/" not in the assets folder. It was the only way I found to make the template working.
My blog system have this routes:
When I access "/blog" it serves the index view and it loads all the assets from "assets" and "public". But when I try to access "/blog/" or the matched route "/blog/category_slug/post_slug" rails tries to load the files from "public/" with this URL:
"base_url/blog/category_slug" and that's really weird!
I'm current using Rails 4.0.2. Any thoughts?
Fixed the problem adding a "/" before the path to the assets:
From: "css/bootstrap.css"
To: "/css/bootstrap.css"
I still don't know why this only happens in the blog controller, but that worked.
Thanks.
I'm writing a jQuery Mobile website to be turned into a PhoneGap/Cordova app. To facilitate this, I created a brand new rails project, and after changing to the 'thin' gem for a webserver, put the entire jQuery Mobile app in the public/myapp folder of the new Rails project.
This all works fine; I can reach my mobile app from localhost:3000/myapp but after a few hours of testing suddenly the Rails app starts throwing 404s all over the place. What is likely to have happened?
This is ONE of the errors I see in the rails server logs:
ActionController::RoutingError (No route matches [GET] "/js/setlocation_address.js"
Basically every single reference in my <head> tag to a javascript or css file returns with a 404 error.
I think the solution was to put
config.serve_static_assets = true
in the config/environments/production.rb file but I'm not sure if this solved the issue as it was an intermittent one.
EDIT
Actually it seems the problem was that I would sometimes go to localhost:3000/myapp and sometimes to localhost:3000/myapp/index.html .
Although Rails would route me to the same index.html page each time, my browser wouldn't pickup the relative paths correctly, and would try to GET localhost:3000/css/styles.css instead of localhost:3000/myapp/css/styles.css.