Skip image missing routing error in development - ruby-on-rails-3

I regularly imports some tables from the production to development environment. One table is related to images, and when I run development, these images all causes ActionController::RoutingError (No route matches [GET] "/uploads/xxx.jpg"):.
The listing pages show lots of these images, which flooded my log. I am wondering if one can skip the logging of these routing error (for missing images only) in the development environment?
I have tried using rescue_from but it does not seem to work, and it is not fine-grain enough.

The new configuration level changes are not applied until server is restarted. Restarting the server should apply new routes. Also share the result of $ rake routes in terminal.

Related

Host Blazor WASM in S3 bucket

I am trying to host my Blazor WASM application on my S3 bucket under a sub path, but I can't really get it to work like I would expect it to.
In order to get it to work, I had to make some changes which I would've preferred not needing to make, especially since they break the application on my development build, so I always have to change between the 2 when I publish / want to develop
In my application I have 2 pages, lets say page1 and page2. On application startup, I want to see page 1. this page has the #page "/" on top. The other page has #page ="/page2". These same paths are then found in my NavMenu.razor.
Now locally I don't care for sub paths, so I'm fine with the application being hosted at localhost:port/ which would go to page 1, and localhost:port/page2 which would go to page 2. In order to get it working in my S3 bucket however, where my application is hosted under s3Url/subpath/{published files}, I had to make some changes: in my index.html I put the
I find myself unable to make all of these changes through appsettings or environment, which makes it time consuming, and error prone to accidentally make errors and push the wrong settings to my s3 bucket when i publish.
Is there any way to handle a sub path better? In the documentation I found this the following article where they talk about this exact issue, and they say it can be fixed by running it locally using this command:
dotnet run --pathbase=/{RELATIVE URL PATH (no trailing slash)}
but even if I do that, since I had to edit all page names and nav links it still doesn't work.
I feel like there must be a better way for me to handle this, so that it works on both development and also on publish, without having to make additional code changes whenever I publish, and then undoing them again when I want to develop locally.

Rails 4 images in public folder are not loading on Apache development

I am new to rails. I am working on a sample application for social networking. I have managed to upload the profile picture of users manually (By copying the image uploaded to /tmp/image to the public folder- public/images/tmp/image) and saved the path to db as avatar_url.
In the profile view I used
<%= image_tag(#userinfo.avatar_url, :alt=>"Avatar image")%>
and getting the picture when running on the rails server.
But after that I have deployed the app in apache with passenger in the development environment by setting RailsEnv development. After that the images are not loading. I tried to go to myip:80/public/images/tmp/image, and it gives Routing Error.
After searching on the web, I found that adding config.serve_static_assets = true in production.rb will solve the problem in production. But no use for me because it also stated that the static files will serve in development by default. For confirming the problem again, I started the rails server and opened localhost:3000/profile, image is there and not getting the image in myip:80/profile.
So do I need to add any other config. Or am I not supposed to do that in this way.
Finally, I got the solution for my problem. Just sharing here.
The problem was actually because of permission issues. The picture will be created in a root temp directory on the form submission. Then I copied the image form the temp folder to the public folder. Hence it has only read permissions. After I deployed it, the image gets returns 403 forbidden error.
I used,
FileUtils.chmod 775, target
to set the permission. After that it worked well.
The option config.serve_static_assets = true tells rails to serve the static assets for your application, but that job should really be left to Apache.
Your issue sounds more related to your Apache configuration than rails.
I would take a look at a tutorial on how to configure Apache and Passenger to make sure your environment is setup correctly.
Anything in the public folder should be served by the web server. However myip:80/public/images/tmp/image is not a valid path. You would need to also have a filename at the end with an extension.

Plesk vs rails3 assets

I took over a clumsily-installed Rails app. Its assets are broke. Chrome Audit returns:
> Leverage browser caching
The following resources are missing a cache expiration.
Resources that do not specify an expiration may not be cached by browsers:
jquery-1.8.3.js
jquery-ui-1.8.17.custom.min.js
rails.js
application.js
jquery.ui.base.css
jquery.ui.theme.css
...etc.
This obviously churns our network. Wat do? Where in Rails-land, or Plesk's vhost.conf file, does one add a line of configuration so the correct HTTP headers go out?
Please don't tell me "just rebuild the assets" - the rebuild is slightly broken.
have a look at Andre Spannig's page if you like tweak the web server configuration for your current domain only: Plesk 10 and vhost.conf.
This helped me once on a different issue.
There may be a better way through Rails but I am not aware of one right now.

What are the typical environments that a rails application should have, and what are their responsibilities?

Typically, I am used to a: local, local-test, dev(dev.site.com), and prod(site.com).
With rails local being 'development' it messes up all of my lingo of what's what. What do you guys typically call each environment in rails and what are each one's responsibilities?
I am aware that I can change development to be local and will probably do that in the near future, as the rails default.
Default environments include development, test, and production.
Development: Typically used on your local machine, where you do all of your coding. Contains more verbose error messages than production, doesn't compress or precompile assets, and doesn't cache classes or controllers (so you can reload your browser and see changes immediately)
Test: A special environment for running tests in without affecting your development database (db is wiped clean between tests).
Production: Final destination. Used for your production/deployment server, where you want maximum performance and minimum verbosity. Debug information is hidden from the user, assets are compressed and precompiled, and caching is enabled -- because code isn't expected to change much between executions.
As Dave mentioned, some people add a staging environment as a sort of middle ground between development and production, to test their app on their remote server. It's often just a matter of copying config/environments/production.rb to config/environments/staging.rb and adding an entry to database.yml so your staging changes don't affect the production database.

Routing to a Location on the Server

I have several custom routes in my rails 3.0 app, the simplest one of which is.
match "*user", "profile#index", :via => :get
Because of that route physical locations on the server are killed. As an example.
/images/rails.png
tries to route to the images user.
I also have to be able to setup where people access
/<username>/archive.zip
So
/buddy/archive.zip
Where the archive.zip is a physical file on the server that has been generated and put there. How can I achieve this in my routing.
For the later I have an actual folder structure in a root folder for /<username>/archive.zip so I was thinking somem sort of symlink would be easy, but without being able to hit physical locations on the server. I am kind of stuck/confused.
Any help is appreciated.
You probably want to have any static assets get handled by your web server before hitting your rails stack. This is generally done by setting the document root in your webserver to the public/ directory within your rails app to serve your static images/css/js.
This is greatly preferred over allowing Rails to serve static assets because web servers are much faster at handling these sorts of requests, and your not tying up your rails processes for these requests, which are often limited to less than a handful.