Rails: "Permission denied - /tmp/cache/assets/development/sprockets/..."? - ruby-on-rails

When I run a rails app and navigate with browser to them I get an error from rails:
Permission denied - /path/to/my_rails_app/tmp/cache/assets/development/sprockets/37b5a12047376b10a57191a10d3af30a rails error
And I have no such file/folders behind the ./tmp/. What is the problem?

I experienced this same issue.
Permission denied # apply2files
The problem is that tmp directory in your application directory is not writable to the current user, that is, the current user does not have permission to write to the tmp directory in your application directory.
Here's how I solved it:
Simply delete the tmp directory in your application directory with superuser rights:
sudo rm -rf tmp
Do not recreate the tmp directory again, it's a waste of effort
Simply start your application and the tmp directory will be created automatically again:
rails s
That's all.
I hope this helps

The user who created or 'owns" the my_rails_app directory isn't writable by the server.
chown -R webserveruser:webserveruser /path/to/my_rails_app
Change the webserveruser to http, or apache or whatever username is running your server. The entitiy to the right of the : is the group, use a group name that is writable by your user if you need write access without changing users.

The reason this error was happening for me was because I was running
ruby bin/rails server
instead of
ruby bin/rails server -e development

try this:
rm -rf public/assets
rake assets:clean RAILS_ENV=development
chown -R nginx:nginx /www/rblpt/

Related

Rails app accidentally installed in root folder

I accidentally created a Rails app in my root directory. I ran the following command and got an error:
rails new test_app
Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.
So I tried running
bundle exec rails server
and it looks like the server is listening on port 3000.
How do I remove this app from my root directory?
Just delete the folder or you can execute this command
rm -rf test_app
Hoping you're on *nix based system.
Stop the running server using:
kill -9 $(lsof -t -i :3000)
Change working directory to root using:
cd /
or wherever you're defining your root as.
Remove the accidentally created Rails application directory using:
rm -fr rails_project_in_root_dir
where rails_project_in_root_dir is the Rails application directory in your root directory.
Okay, I'm not sure how it got installed in the root directory, but I ended up just manually deleting all the folders and files that get created when you run
rails new app
Here's where I found the list of files:
http://guides.rubyonrails.org/getting_started.html
That ended up resolving the issue. Thanks for the help guys.

Log File ownership in Rails

Rails 3.2.18
Ruby 2.15
I inherited a Rails application that I am trying to decipher. In environments/production.rb, I have:
config.logger = Logger.new(config.paths['log'].first, 100, 10485760)
config.log_tags = [ lambda {|r| DateTime.now } ]
which is going to create a log file in the log folder and when it reaches 10MB it ages it and keeps 100 in the folder.
When I look at the folder, I see that the owner of these files is root. How do I make sure the owner is the user and not root? For instance, if the application is deployed in /home/myapp, I want the owner to be the myapp user. The real side issue I'm having is that if I am logged in as the myapp user and try to precompile assets, it fails because the log file is owned by root.
Permissions are always a pain. You'll likely want to run something like this:
sudo chown -R myapp_user /home/myapp
or
sudo chown -R myapp_user:myapp_user /home/myapp
if you want the group to be set as well. This requires the user you are running as to have sudo permissions. If you don't have sudo permissions you'll have to login as root and execute the command above.

Rails Cache Permission Error

I have a Rails app (a Spree Commerce store) running on Digital Ocean and deployed through Cloud 66.
I would like to SSH into my server, run a rails console, and adjust some Spree config settings. When I try to do this I get a permissions error:
Errno::EACCES: Permission denied # dir_s_mkdir -
/var/deploy/my-app/web_head/releases/20150220220517/tmp/cache/29B
According to the Spree Developer Guide's page on preferences, this is because preferences are cached into memory to improve performance. The problem (I think) is that my user doesn't have write access to the tmp/cache directory, and it is my user that is running the rails console.
If I ls -l on the $STACK_PATH/tmp/cache directory I get the following:
> lrwxrwxrwx 1 nginx nginx 43 Feb 20 22:05
> tmp/cache ->
> /var/deploy/my-app/web_head/shared/cache
I figure I need to give my user write access to the directory, like the nginx user has. I tried adding myself to the nginx user group, but that didn't seem to have any effect. What can I do to prevent this permissions error?
Ok, I figured it out based on this question and answer on Cloud 66's support forum.
I changed the group owner of the cache folder to app_writers, a group that my user is a part of. The Cloud 66 way to do this is with a deploy hook. Here's the yml file that worked for me:
production:
after_rails:
command: chown nginx:app_writers /var/deploy/my-app/web_head/current/tmp/cache && chmod -R 775 /var/deploy/my-app/web_head/current/tmp/cache
target: rails
run_on: all_servers
sudo: true

Rails / Carrierwave / GIT / nginx / Capistrano - can't create a directory in git releases folder

I'm using carrierwave in a rails app to upload files. It works fine on my development environment, but on my production VM (Ubuntu), I'm getting this error:
An Errno::EACCES occurred in users#update:
Permission denied - /home/yards/apps/yardsapp/releases/20130616143623/public/uploads/tmp/20130616-1438-14186-3184
/usr/local/lib/ruby/1.9.1/fileutils.rb:244:in `mkdir'
I'm pretty sure I understand what is going on, but I can't seem to figure out a fix. My capistrano deploy.rb is set up with the user as root. So when it creates the new release folder on a deploy, the access rights are for root (I think).
Then when I try to upload a file, I get that error because nginx is trying to execute a mkdir as www-data.
I could chown the folder after the deploy and it works...but then another deploy creates another new directory with owner set to root as default.
At least I think this is what is going on. Does anyone have any ideas on how I should be doing this?
Run your deployment as www-data. You might need to adjust the authorized_keys file for the www-data user as well to be able to connect.
To fastest way would be to copy over your authorized_keys file for whatever user you are using at the moment (assuming you are root):
mkdir $WWW_DATA_HOME/.ssh
cp ~/.ssh/authorized_keys $WWW_DATA_HOME/.ssh/authorized_keys
chown www-data:www-data $WWW_DATA_HOME/.ssh/authorized_keys
You might also need to change the shell for the www-data user to log in to it:
chsh -s /bin/bash www-data
Now you should be able to do
ssh www-data#your-host.tld
and log in.
What this came down to was an improper Capistrano configuration. I followed the capistrano docs correctly (and made a 'deployer' user, same thing as the www-data as suggested above) and I have capistrano working like a charm. Also upgraded to Capistrano 3.

Rails/Devise Errno::ENOENT on lockfile after server crash

I've got a Rails 3.2.5 app using Devise, with OpenID for authentication (Google), running on nginx/unicorn.
Today, my server crashed. I restarted. Now sign-in is not working. Here's what happens:
Signed-out user accesses app
Signed-out user redirected to /users/sign_in
User clicks 'Sign-in with GMail' button
500 error. In the log file, I see:
Started GET "/users/auth/google" for ...
Errno::ENOENT (No such file or directory - /tmp/temp/tmp20120801-4155-1scxc9o.lock):
How can I resolve this error? I'm not even sure where to begin.
It was an access issue. Not sure of the root cause, but no doubt it has something to do with some mistake I made when configuring the app.
To resolve:
$ cd /tmp
$ chmod 777 temp
$ chmod 777 associations
$ chmod 777 nonces
Make sure your OpenID filestore is setup correctly, ie..
OpenID::Store::Filesystem.new('./tmp')
(Notice the . in front of the /tmp)

Resources