Peter Boomsma

Joined

380 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Show each users each post.

I'm trying to create a page where all my users are listed, and every movie they've added to their account.

My UserController index def

def index
  @users = User.all
  if logged_in?
    @user = User.find(session[:user_id])
    @movies = @user.movies
  end
end

And my user index.html.haml

#content#users
  - @users.each do |user|
    %li
      = link_to user.name, user
      .movie
      - @movies.each do |movie|
        .movie-frame
          = movie.title
          = image_tag(movie.image)

At the moment the -@movies.each do shows all the movies that are added to my database, it does this for every user. And not specifically the movies that that user has in his account. How do I show each movie for each user?

Posted in Capistrano deploy removes tables from database.

You're completly right. I also posted the question on StackOverflow > http://stackoverflow.com/questions/26736507/capistrano-deploy-removes-table/26736546?noredirect=1#comment42063814_26736546 if anyone wants a more detailed answer on the question.

Posted in Capistrano deploy removes tables from database.

I use capistrano to deploy my Rails app to my VPS, but after every deploy when I visit my page I get an error. The log says:

I, [2014-11-04T08:20:16.659289 #12482]  INFO -- : Started GET "/" for 82.73.170.71 at 2014-11-04 08:20:16 -0500
I, [2014-11-04T08:20:16.662717 #12482]  INFO -- : Processing by HomeController#index as HTML
I, [2014-11-04T08:20:16.665979 #12482]  INFO -- : Completed 500 Internal Server Error in 3ms
F, [2014-11-04T08:20:16.670152 #12482] FATAL -- :
ActiveRecord::StatementInvalid (Could not find table 'users'):
  app/controllers/application_controller.rb:18:in `current_user'
  app/helpers/sessions_helper.rb:26:in `logged_in?'
  app/controllers/home_controller.rb:4:in `index'

I have to ssh into my VPS and go to my Rails root and run RAILS_ENV=production bundle exec rake db:migrate . In my db folder I do still have the production.sqlite3 file, but it's empty.

My deploy.rb

# config valid only for Capistrano 3.1
lock '3.1.0'

set :application, 'movieseat'
set :repo_url, 'git@github.com:alucardu/movieseat.git'

set :deploy_to, '/home/deploy/movieseat'

set :linked_files, %w{config/database.yml config/secrets.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

require 'capistrano-rbenv'

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :publishing, 'deploy:restart'
  after :finishing, 'deploy:cleanup'
end

So why is Capistrano removing my database when I deploy?

Posted in could not connect to database postgres

I'm trying to install postgresql but I'm running into an error when I try to create a user:

createuser: could not connect to database postgres: could not connect to server: No such file or directory
  Is the server running locally and accepting
  connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Posted in Getting a 403 on Ubuntu + Nginx

deploy@movieseat:~$ ls -la /home/deploy/movieseat/current/
total 92
drwxrwxr-x 11 deploy deploy 4096 Nov  2 08:33 .
drwxrwxr-x  7 deploy deploy 4096 Nov  2 08:33 ..
drwxrwxr-x  2 deploy deploy 4096 Nov  2 08:33 .bundle
-rw-rw-r--  1 deploy deploy  466 Nov  2 08:29 .gitignore
-rw-rw-r--  1 deploy deploy    6 Nov  2 08:29 .ruby-version
-rw-rw-r--  1 deploy deploy  982 Nov  2 08:29 Capfile
-rw-rw-r--  1 deploy deploy 2376 Nov  2 08:29 Gemfile
-rw-rw-r--  1 deploy deploy 5099 Nov  2 08:29 Gemfile.lock
-rw-rw-r--  1 deploy deploy    0 Nov  2 08:29 README.md
-rw-rw-r--  1 deploy deploy  478 Nov  2 08:29 README.rdoc
-rw-rw-r--  1 deploy deploy  249 Nov  2 08:29 Rakefile
drwxrwxr-x  9 deploy deploy 4096 Nov  2 08:29 app
-rw-rw-r--  1 deploy deploy 5534 Nov  2 08:33 assets_manifest_backup
lrwxrwxrwx  1 deploy deploy   33 Nov  2 08:33 bin -> /home/deploy/movieseat/shared/bin
drwxrwxr-x  6 deploy deploy 4096 Nov  2 08:33 config
-rw-rw-r--  1 deploy deploy  553 Nov  2 08:29 config.database.yml.sqlite3
-rw-rw-r--  1 deploy deploy  154 Nov  2 08:29 config.ru
drwxrwxr-x  3 deploy deploy 4096 Nov  2 08:50 db
drwxrwxr-x  4 deploy deploy 4096 Nov  2 08:29 lib
lrwxrwxrwx  1 deploy deploy   33 Nov  2 08:33 log -> /home/deploy/movieseat/shared/log
drwxrwxr-x  3 deploy deploy 4096 Nov  2 08:33 public
drwxrwxr-x  8 deploy deploy 4096 Nov  2 08:29 test
drwxrwxr-x  2 deploy deploy 4096 Nov  2 08:33 tmp
drwxrwxr-x  3 deploy deploy 4096 Nov  2 08:33 vendor
deploy@movieseat:~$ 

I've found someone else who has the same problem > http://stackoverflow.com/questions/26348436/rails-4-2-nginx-application-root-wont-load

I'm running RAILS_ENV=production rails s on my local machine and I got the same error now.

Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`

I've created a secret by using rake:secret, but when I add to it my secrets.yml like this:

production:
  secret_key_base: 9c9fc2f9a0a212bb2bc5be64ec3bb722fc5ae01d79c1ed181f1b3a8e858c25f076e7845b67f75ab658947557d81c7fc08ba5bddf20860ec5d681b701be05***

I get a

We're sorry, but something went wrong.
If you are the application owner check the logs for more information.

But the log is empty. So I'm trying to fix this problem first, so I can run development locally.

Posted in rbenv: bundle: command not found

Yes sorry. I've just opened another question. Might be easier to track for people who also have the problem, instead of searching through a endless topic.

Posted in rbenv: bundle: command not found

Hm I've added the secrets.yml and database.yml to my deploy.rb, commited it to my git and added the files to my production server and then deployed. But I'm getting a:

An error occurred.

Sorry, the page you are looking for is currently unavailable.
Please try again later.

If you are the system administrator of this resource then you should check the error log for details.

Faithfully yours, nginx.

Message on my website.

Posted in Getting a 403 on Ubuntu + Nginx

My error log outputs the following,

[ 2014-11-02 04:18:12.0511 23504/7f64e6a36780 agents/Watchdog/Main.cpp:538 ]: Options: { 'analytics_log_user' => 'nobody', 'default_group' => 'nogroup', 'default_python' => 'python', 'default_ruby' => '/usr/bin/ruby', 'default_user' => 'nobody', 'log_level' => '0', 'max_pool_size' => '6', 'passenger_root' => '/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini', 'passenger_version' => '4.0.53', 'pool_idle_time' => '300', 'temp_dir' => '/tmp', 'union_station_gateway_address' => 'gateway.unionstationapp.com', 'union_station_gateway_port' => '443', 'user_switching' => 'true', 'web_server_passenger_version' => '4.0.53', 'web_server_pid' => '23503', 'web_server_type' => 'nginx', 'web_server_worker_gid' => '33', 'web_server_worker_uid' => '33' }
[ 2014-11-02 04:18:12.0628 23507/7f544fe55780 agents/HelperAgent/Main.cpp:650 ]: PassengerHelperAgent online, listening at unix:/tmp/passenger.1.0.23503/generation-0/request
[ 2014-11-02 04:18:12.1029 23512/7fd0a6b6b7c0 agents/LoggingAgent/Main.cpp:321 ]: PassengerLoggingAgent online, listening at unix:/tmp/passenger.1.0.23503/generation-0/logging
[ 2014-11-02 04:18:12.1035 23504/7f64e6a36780 agents/Watchdog/Main.cpp:728 ]: All Phusion Passenger agents started!
[ 2014-11-02 04:18:12.1191 23512/7fd0a6b6b7c0 agents/LoggingAgent/Main.cpp:289 ]: Caught signal, exiting...
[ 2014-11-02 04:18:13.1537 23534/7f9940e05780 agents/Watchdog/Main.cpp:538 ]: Options: { 'analytics_log_user' => 'nobody', 'default_group' => 'nogroup', 'default_python' => 'python', 'default_ruby' => '/usr/bin/ruby', 'default_user' => 'nobody', 'log_level' => '0', 'max_pool_size' => '6', 'passenger_root' => '/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini', 'passenger_version' => '4.0.53', 'pool_idle_time' => '300', 'temp_dir' => '/tmp', 'union_station_gateway_address' => 'gateway.unionstationapp.com', 'union_station_gateway_port' => '443', 'user_switching' => 'true', 'web_server_passenger_version' => '4.0.53', 'web_server_pid' => '23533', 'web_server_type' => 'nginx', 'web_server_worker_gid' => '33', 'web_server_worker_uid' => '33' }
[ 2014-11-02 04:18:13.1632 23537/7fa7dc711780 agents/HelperAgent/Main.cpp:650 ]: PassengerHelperAgent online, listening at unix:/tmp/passenger.1.0.23533/generation-0/request
[ 2014-11-02 04:18:13.1788 23542/7fd3b4c307c0 agents/LoggingAgent/Main.cpp:321 ]: PassengerLoggingAgent online, listening at unix:/tmp/passenger.1.0.23533/generation-0/logging
[ 2014-11-02 04:18:13.1792 23534/7f9940e05780 agents/Watchdog/Main.cpp:728 ]: All Phusion Passenger agents started!
[ 2014-11-02 04:40:54.6081 25129/7fd334fd9780 agents/Watchdog/Main.cpp:538 ]: Options: { 'analytics_log_user' => 'nobody', 'default_group' => 'nogroup', 'default_python' => 'python', 'default_ruby' => '/usr/bin/ruby', 'default_user' => 'nobody', 'log_level' => '0', 'max_pool_size' => '6', 'passenger_root' => '/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini', 'passenger_version' => '4.0.53', 'pool_idle_time' => '300', 'temp_dir' => '/tmp', 'union_station_gateway_address' => 'gateway.unionstationapp.com', 'union_station_gateway_port' => '443', 'user_switching' => 'true', 'web_server_passenger_version' => '4.0.53', 'web_server_pid' => '25128', 'web_server_type' => 'nginx', 'web_server_worker_gid' => '33', 'web_server_worker_uid' => '33' }
[ 2014-11-02 04:40:54.6228 25132/7fe9a63c6780 agents/HelperAgent/Main.cpp:650 ]: PassengerHelperAgent online, listening at unix:/tmp/passenger.1.0.25128/generation-0/request
[ 2014-11-02 04:40:54.6460 25137/7f157336b7c0 agents/LoggingAgent/Main.cpp:321 ]: PassengerLoggingAgent online, listening at unix:/tmp/passenger.1.0.25128/generation-0/logging
[ 2014-11-02 04:40:54.6464 25129/7fd334fd9780 agents/Watchdog/Main.cpp:728 ]: All Phusion Passenger agents started!
2014/11/02 04:40:55 [error] 25150#0: *1 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"
2014/11/02 04:40:59 [error] 25150#0: *1 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"
2014/11/02 04:41:57 [error] 25150#0: *1 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"
2014/11/02 04:41:59 [error] 25150#0: *1 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"
2014/11/02 04:41:59 [error] 25150#0: *1 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"
2014/11/02 04:43:10 [error] 25150#0: *2 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"
2014/11/02 04:43:11 [error] 25150#0: *2 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"
2014/11/02 04:43:12 [error] 25150#0: *2 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"
2014/11/02 04:43:12 [error] 25150#0: *2 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"
2014/11/02 04:43:12 [error] 25150#0: *2 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"
2014/11/02 04:43:12 [error] 25150#0: *2 directory index of "/home/deploy/movieseat/current/public/" is forbidden, client: 82.73.170.71, server: localhost, request: "GET / HTTP/1.1", host: "178.62.204.53"

Update #1

I've added a index.html file to my public folder and deployed again, now when I visit the ip adres the website shows that index.html file. So it looks like nginx wasn't able to find a index.html file in my public folder. Which is to be expected since Rails doesn't work that way. How would I direct "this" to my Rails app?

Posted in rbenv: bundle: command not found

By the way, a question about the guide.

Find the following lines, and uncomment them:

# passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.1.2/ruby; # If use use rvm, be sure to change the version number
# passenger_ruby /home/deploy/.rbenv/shims/ruby; # If you use rbenv

I don't have these two lines in my /etc/nginx/nginx.conf file. Should I add the following line?

passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.1.2/ruby; # If use use rvm, be sure to change the version number

By the way, a few more things you might want to add or revise.

I had to add sudo apt-get install nodejs to my server, otherwise I got a ExecJS::RuntimeUnavailable error. Also how to create a database.yml file on the server would help.

Posted in rbenv: bundle: command not found

Yup, just did a gem install bundler and it's working now.

The deploy doesn't get aborted now but when I go to my IP I only see the Welcome to nginx! Message. I did change this though:

root         /home/deploy/movieseat/current/public;

After restarting the nginx server I get a 403 Forbidden message on the site.

Posted in rbenv: bundle: command not found

Alright I've done all the steps again (also the guide doesn't really mention how to create the database.yml file) and again I get the same error.

rbenv: bundle: command not found

deploy@movieseat:~$ which gem
/home/deploy/.rbenv/shims/gem

deploy@movieseat:~$ which ruby
/home/deploy/.rbenv/shims/ruby

deploy@movieseat:~$ which gem
/home/deploy/.rbenv/shims/gem

deploy@movieseat:~$ which bundle
/usr/bin/bundle

If I run the which bundle command on my local machine I get

alucardu@alucardu-VirtualBox:~/sites/movieseat$ which bundle
/home/alucardu/.rbenv/shims/bundle

It seems that on my VPS my bundle path isn't correct. Is that the case? If so, how can I change that?

I have opend my vi ~/.bashrc file on the VPS, but I'm not sure what to check or edit.

At the bottom of the file I see

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

Posted in rbenv: bundle: command not found

I've removed the droplet and started over. Hoping I did something wrong the first time. By machine, you mean the local or the VPS machine?

Posted in rbenv: bundle: command not found

I'm trying to deploy my Rails app on my Digital Oceans VPS but I'm running into a error:

Running cap production deploy ends up with this error:

INFO[7cd03924] Running ~/.rbenv/bin/rbenv exec bundle install --binstubs /home/deploy/movieseat/shared/bin --path /home/deploy/movieseat/shared/bundle --without development test --deployment --quiet on 178.62.204.53
DEBUG[7cd03924] Command: cd /home/deploy/movieseat/releases/20141101124751 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 ~/.rbenv/bin/rbenv exec bundle install --binstubs /home/deploy/movieseat/shared/bin --path /home/deploy/movieseat/shared/bundle --without development test --deployment --quiet )a
DEBUG[7cd03924] rbenv: bundle: command not found

On my VPS I've done:

deploy@movieseat:/$ which bundle
/usr/local/bin/bundle

And:

deploy@movieseat:/$ rbenv which bundle
rbenv: bundle: command not found

I've also checked:

deploy@movieseat:/$ bundle -v
Bundler version 1.7.4

Does anyone know what's going wrong here?

Update
Added some commands.

deploy@movieseat:/$ rbenv version
2.1.2 (set by /home/deploy/.rbenv/version)
deploy@movieseat:/$ gem install bundler
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /var/lib/gems/2.1.0 directory.
deploy@movieseat:/$ sudo gem install bundler
Successfully installed bundler-1.7.4
1 gem installed

Posted in rbenv: 2.1.2 is not installed or not found

I'm trying to deploy my local Rails app to my Digital Ocean VPS using the GoRails guide > https://gorails.com/deploy/ubuntu/14.04

But I'm running into a error when I want to deploy:

cap production deploy

Results in

alucardu@alucardu-VirtualBox:~/sites/movieseat$ cap production deploy
DEBUG[790313df] Running /usr/bin/env [ -d ~/.rbenv/versions/2.1.2 ] on 178.62.204.53
DEBUG[790313df] Command: [ -d ~/.rbenv/versions/2.1.2 ]
DEBUG[790313df] Finished in 0.380 seconds with exit status 1 (failed).
ERRORrbenv: 2.1.2 is not installed or not found in ~/.rbenv/versions/2.1.2
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 178.62.204.53: exit

SystemExit: exit

Tasks: TOP => rbenv:validate

I've found this topic > https://gorails.com/forum/ruby-issue-when-doing-cap-deploy-production which has the same issue, but the fix they use

set :rbenv_ruby, '2.1.2'

Doesn't work, because I allready state the following in my Capfile

require 'capistrano/rbenv'
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.1.2'

Can someone point out what the problem is?

Update

When I run:

which ruby

I get:

/home/alucardu/.rbenv/shims/ruby

When I check my files I can go to /home/alucardu/.rbenv/versions/2.1.2, so it should all be there.

Update

Looks like I was installing rbenv on my local server instead of my VPS. Doing that now.

Update

Yup, quite stupid of me. Pretty much done now!