Rails_admin works on my development server with port :3000,
but not working on production server, responds 404 error!
How to get it working on production server ?
Thanks
Have you tried running the following?:
$ rake rails_admin:copy_assets
Spotted this little bit in the GitHub ReadMe:
When running RailsAdmin in production the images, stylesheets,
and javascript assets may return 404
not found error's depending on your
servers static assets configuration.
To prevent this issue you can copy
assets directly into your application
by running:
$ rake rails_admin:copy_assets
I had to do a RAILS_ENV=production bundle exec rake db:reset, then it worked. Don't know whether it was a user session issue (no privileges?) or something else.
Be careful though not to execute the command above if you have "real" data in your database!
Related
I did my first deploy with a very simple rails app today on a Digital Ocean droplet running Ubuntu 14.04. I deployed following this article
https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma
and only replaced RVM with rbenv.
Now I get the "We're sorry, but something went wrong." Rails error page. My production.log says the following:
D, [2016-02-13T15:58:41.165515 #1783] DEBUG -- : ^[[1m^[[36mActiveRecord::SchemaMigration Load (1.5ms)^[[0m ^[[1mSELECT "schema_migrations".* FROM "schema_migrations"^[[0m
Puma logs are clean though. I had some trouble with rake in the first place, as migrations weren't executed by capistrano itself. So I updated rake from 10.4.2 to 10.5 and executed the migrations manually, but still the same error. Thanks in advance.
EDIT:
What I just noticed is that my public folder looks like this:
404.html 422.html 500.html assets favicon.ico robots.txt
As this is nginx' root folder, how is the app supposed to load in any way? As I said, this is my first deploy.
Puma logs are clean, but I bet Rails ones aren't. They're located under RAILS_ROOT/log directory, you probably want the production one.
My guess, without seeing those logs are that it's one of the following, ordered by likelihood:
You do not have a secret token generated which is done using rake secret and placing it in an environment variable. Check config/secrets.yml.
Bad database connection
Ruby environment is wrong, a certain gem is missing
It should be one of these three things. Check the log file first, though and maybe post it as an edit
Rails is letting you know that migrations need to be run by trying to load the schema so:
RAILS_ENV=production rake db:migrate assets:precompile
Sorry if this question sounds basic. But I haven't been able to find an answer anywhere on the web...
I'm currently running my Rails app on a Ubuntu server. Until now I've always shut down the production app before I pull the changes, run rake assets:clean assets:precompile, and only boot up the Rails app again once the process is finished.
I'm not sure whether the shutting down of app is necessary(i.e. if I don't do it, my app will behave erratically). It induces about 5 minutes of down time.
If that's a must, then maybe I should try to do local precompilation/more advanced deployment procedure, in order to reduce downtime? (Tried local compilation according to http://guides.rubyonrails.org/asset_pipeline.html#local-precompilation, but then after deleting original public/assets and pulling locally precompiled public/assets from the repo, the production server was having rack timeout all the time and won't render anything.)
YES you run rake assets:precompile Rails looks through your assets folder and copies over everything that is not Javascript or CSS into public/assets. It then creates application.js by reading app\assets\javascripts\application.js, and application.css by reading app\assets\stylesheets\application.css, loading up all the "require" files it finds in there.
So yes..you can do it ..but if you ran rake assets:clean..and then precompile...then public/assets will be updated with new compiled assets.
Dont forget to restart the server :)
I have locally made this website on my local Linux Debian 6 under path /HOME/ADMIN/WWW/WEBSTUDIO and I need it to be published on my virtual server.
Is "precompiling" the actual word? I know about the command 'rails server' but that is clearly not the same thing as it makes no alterations on the PUBLIC folder.
I guess I have to first transfer my directory structure to server (has Apache2 and ISPCONFIG3 already) and I have done everything so far as how it is described here, but it doesn't tell how to put and precompile your site into Prod Mode.
So what's the procedure? ONLY the basic steps.
When you run rails server or rails s for short your start the rails server
The precompilation isn't for the code, it's for the assets (css,js,fonts, images, etc), rails compiles all css and js each to a single file to reduce the number of http requests needed to load the site.
Also if you are using scss, less or any of those files that need processing it would be done during the precompilation, and if any gems contain assets it would be copied to the public folder.
The precompilation command as mentioned in other answers/comments is
rake assets:precompile
On server terminal, from the root of the project, run:
RAILS_ENV=production rake assets:precompile
I'm testing my Rails 4 app in the production environment on my localhost:3000 using the built in Webrick server. When I run RAILS_ENV=production bundle exec rake assets:precompile the assets are rebuilt in public and the manifest is rebuilt, but the pages are still being served with the previous asset names.
Restarting the rails server makes the new assets appear. Is there a less extreme way to achieve this and how will this behave when I port this to my production server running Phusion Passenger. I really don't want to restart Apache to get my assets in gear.
If you did not change the contents of assets, the precompiled version will be as same as the previous one. If you change it even a bit, the fingerprint will change and app will request for the new one only as you have set config.assets.digest = true.
Anyway another work around would be:
Just run:
rake assets:clean
and then,
rake assets:precompile
This makes everything in the asset pipeline to be rebuilt and serve freshly.
Rails automatically clear the cache for every individual file when its contents are edited.
If any of the above did not work, please try as below:
config.serve_static_assets = true in config/environments/production.rb
config.serve_static_assets configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won't be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.
Ref: http://guides.rubyonrails.org/configuring.html#rails-general-configuration
Hope it helps :)
We faced the same problem where the old assets were being served even after trying rake assets:clean or assets:clobber and eventually server reboot would resolve the issue. The culprit in our case was unicorn. While deploying our rails app using mina and mina-unicorn, we ran rake assets:clobber, then compiled assets and then restarted unicorn in the end. By doing this the unicorn master never gets stopped and continues to show old assets. So, we changed our mina deploy script and instead of restarting unicorn, we stopped unicorn and started it back. This resolved the issue. So, the key steps are
Deploy application
run rake assets:clobber
run rake assets:precompile
stop unicorn
start unicorn
This kills the concept of zero downtime but this is a better solution than restarting the server.
I understand that you use passenger but this information can be helpful for others
You can recompile your rails assets by running the following command:
bin/rails assets:precompile RAILS_ENV=development
en:
activemodel: # or activerecord:
errors:
models:
person:
# Override the format for all Person attributes:
format: "Invalid %{attribute} (%{message})"
attributes:
age:
# Override the format for the age attribute:
format: "%{message}"
blank: "Please fill in your %{attribute}"
I'm having a big problem right now. My site is written in Ruby on Rails, and I'm using the active merchant gem to interface with PayPal. The site is hosted on heroku.
I have an API key and API signature set as config variables in my heroku app. However, I still get the error:
Running: rake assets:precompile
(in /tmp/build_3pvaswdp7wvca1)
rake aborted!
An API Certificate or API Signature is required to make requests to PayPal
(See full trace by running task with --trace)
I can run heroku run rake assets:precompile separately and that works completely fine.
Furthermore, my staging site has the exact same config variables (RACK_ENV and RAILS_ENV are set to production on the staging site btw) set on my staging site and that seems to be working fine. However, my production site crashes.
Any ideas on what might be happening / how to fix this issue?
I just found out about this command:
heroku labs:enable user-env-compile -a myapp
BUT it is experimental.