I amm using Rails 5, and I have half way deployed my app through Capistrano on server. due to specific need to loadschema, i ssh in and cd into the release/### directory and tried to run
rails --version # came out 5.0.3beta
bundle # works, everything installed
rails c # but this fail
running rails db:migrate also failed.
it seems to return rails generic help as like my directory isn't a rails directory.
i tried deleting bin folder, but still the same.
anyone know what could be wrong?
thank you
It seems you're using capistrano to deploy your application. Have a look at this issue: https://github.com/capistrano/bundler/issues/45
The solution would be:
remove bin from the linked_dirs
add set :bundle_binstubs, nil to your config/deploy.rb to generate the binstubs
To run the console try rails console. To run a migration try rake db:migrate
Related
I've deployed a Rails app to AWS using Capistrano, and now I'm trying to start Rails console, but can't. If I go into home/user/app-name/current/ and try running rails c I just get instructions on how to use the rails command.
Alternatively, I need to run a command, specifically a Searchkick command ClassName.reindex is there a way I'm missing to do this without opening the console?
rails c is probably failing due to the fact that you are missing bin/rails in your deployed app. See this answer for a fix: Rails 4 doesn't detect application after capistrano deployment
Once you get bin/rails working, you can run a command without using the console like this:
bundle exec rails runner ClassName.reindex
The runner Rails command loads your app and evaluates whatever Ruby code you supply.
Depending on how you've done your deployment, you may need to explicitly specify the environment, like this:
bundle exec rails runner -e production ClassName.reindex
Take a look at these and let m,e know if you find them to be helpful.
https://github.com/ydkn/capistrano-rails-console
https://gist.github.com/benedikt/1115513
Having a weird issue and need help.
I am trying to start a rails console on a production server and it is acting like the rails c command does not exist.
FWIW, I have been a rails developer for 4 years and do this all the time on a plethora of other servers without issue. On this server, I can drop, create, migrate, seed the database with no problems (using RAILS_ENV=production), and the app works fine live without any issues.
Setup:
Ubuntu 14.04 (racksapce 2nd gen performance 1 server)
Nginx with Passenger (I typically use Unicorn, but have never had a problem on any of the apps I have deployed with Passenger)
Ruby 2.1.5 (using rvm)
Rails 4.1.7
Postgres
Capistrano 3 (using the rvm, migrations, asset-precompilation, etc. extensions)
What I've tried:
cd into app directory:
cd /home/deployer/app_name/current
Which loads .rvmrc and shows that I am in the correct gemset, ran bundle just for kicks.
rails c production # (which usually works no problem)
bundle exec rails c production # (sometimes have to do this on older apps that do not have the newer capistrano 3 and rvm setup)
rails c production RAILS_ENV=production # (getting desperate here)
RAILS_ENV=production rails c production # (haha, surely this won't work, but out of options)
RAILS_ENV=production bundle exec rails console
Every time, I get a notice that implies 'rails c' is not a valid command:
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
..... yada yada, shows the rest of the rails options (oddly enough does not show 'c' or 'console' as options?)
Again, I have logged into hundreds of production consoles on both nginx/apache deployed with old and new versions of both Unicorn and mostly older versions of Passenger.
This is the first time I have ever gotten this message, and the console is the ONLY thing that seems to be broken - everything else works fine! the app is live and works great.
I know that the first thing to be suggested is that I am not running rails c production from the app directory - I have cd'd into the correct directory at least 10 times and manually loaded the correct gemset, this is not the issue.
Can't figure out why it works fine in development, but not in production. I know there used to be a scripts directory a while back (maybe rails 2?)- Is there still a directory that contains the script commands for rails that may have been corrupted?
Has anyone ever experienced this before or have any suggestions?
I feel like I am missing something.
Ok, found the issue... #stoodfarback was pretty close, but I thought the cause of the issue needed to be mentioned for others who might encounter the same thing.
Basically I am using a newer version of Capistrano (3.3.5) than I have used in the past and it (by default) adds 'bin' to the list of shared directories that it symlinks on each deploy.
set :linked_dirs, fetch(:linked_dirs, []).push('bin', 'log', 'tmp', 'public/system', "public/downloads", "public/assets")
So the deploy script created a new directory in shared called bin (which was empty) and the files used to launch rails server and console were missing. They were obviously still there in development, so it only affected production.
Removed 'bin' from the linked_dirs list and everything now works as expected.
now looks like:
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp', 'public/system', "public/downloads","publ ic/assets")
I have noticed on the last few versions of Capistrano that I have used, the format and defaults for linked_dirs keeps changing quite a bit, but I had never seen bin in that list. Not really sure why bin would need to be symlinked... it only has the default rails files and I can't think of why they would need to be removed from source control, but maybe the Capistrano team has a reason.
Hope this helps someone.
Check if you have any of these files and try deleting them:
script/rails
bin/rails
I've successfully made a new application with the rails new command from a clone of the Rails master branch. The app looks fine, and is definitely Rails 4. But when I try to run any other rails command, the prompt gives me:
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
... etc etc
I've tried rails, bundle exec rails, and bin/rails, all give the same prompt. My steps for creating a new Rails 4 app were:
Clone the Rails master branch to my local machine
Create a new rvm gemset, and use it (1.9.3)
Run rails/railties/bin/rails new myapp --edge -T --skip-index-html
cd myapp and run bundle install and bundle update just to be sure
Run any rails command
What am I doing wrong? rvm-prompt suggests I am using the right gemset. One thing I did notice is that even when I remove jbuilder from my Gemfile and run a bundle update, it still appears in my gem list. Is something wrong with my rvm here?
rails-v output is 'Rails 4.0.0.beta'
See my first comment here, it contains a possible fix : https://github.com/rails/rails/issues/9715
This looks like a bug, report back to ruby on rails issues tracking: https://github.com/rails/rails/issues
I had this issue when my 'bin' folder was missing.
i have checked out a rails project into my svn repository.now i want to run that project on my local server.I entered rails server command to run it but i am getting an error that it cant find or read .yml file.what are the steps to be taken after one checks out some rails project in order to run it on local server.
cd into the directory containing the Gemfile and then do either rails s or bundle exec rails s. The error you are describing usually happens to me when I am not in the same dir as the Gemfile and Rails cannot find the database.yml file.
I'm deploying a rails application using Capistrano to a shared server (on WebFaction). This means there are several different Ruby version installed there.
Everything works fine until I want to run some rake tasks. These tasks fail by saying I don't have the right RubyGems version.
From this thread I understood that fixing it would be as easy as adding the full path to the correct rake folder to my rake commands. I tried that but failed again, now because the Ruby interpreter that is used is the wrong one.
I assumed that capistrano would use the username/password I gave it to run commands on the server but it seems not to be the case.
Am I missing something? How can I fix that?
Thanks!
This is indeed a path issue. I solved it by symlinking my ruby, rake, and rails executables to my path. For instance, if the executables that you want (but are failing to work) are located at /opt/ruby/bin/ruby, you'll symlink it to:
ln -s /opt/ruby/bin/ruby /usr/local/bin/ruby