running rails console in Capistrano deployed app - ruby-on-rails

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

Related

Rails 5 console not working when deploying with Capistrano

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

Spring: does "rails server" not start spring?

I'm just wondering: doesn't rails server start spring? It seems, that only rake or rails console starts spring. Is this normal behaviour, or do I have something misconfigured?
I just confused too. Then I find this.
here explained when spring will start
rails console, rails generate, rails runner
These execute the rails command you already know and love. If you run
a different sub command (e.g. rails server) then spring will
automatically pass it through to the underlying rails executable
(without the speed-up).

"Rails server" creates a new app called "server" not start the rails server

I've transferred an older RoR app onto a new workstation and now having issues starting it.
For instance when I attempt to use the "rails server" command it generates a new rails application rather than starting the server.
I did have it running last night but after attempting to use the 'Production' database, apparently the 'rails server -e "production" ' command is obsolete. I therefore tried:
RAILS_ENV=production
And it seems the application was not longer working.
There was also lots of documentation and suggestions to use RVM....which I installed....could that be the cause the 'rails server' command is not starting the server but rather creating a new app?
You should do
RAILS_ENV=production rails s
on rails app dir.
I think your app is on rails 3, with rails 4 installed.
To start the server I had to use: bundle exec rails server what's going on? – paulywill yesterday
Using bundle exec will ensure it uses the version of rails from your Gemfile. This is default behaviour after Rails 3.1 but your app is older than that. – Graeme McLean yesterday

How to run my ruby on rails web app using command prompt (not IDE)

I'm using Aptana as IDE to develop a small application. To test the application, I use the command prompt of Aptana.
Im using a laptop that has command prompt with ruby and rails but not aptana. All I see is a C:Sites>. The application I'm trying to access is located in a different folder.
What should I do the run the ruby on rails application from the prompt?
Thanks for helping
This: cd to your project folder, then rails s or script/server.
Access it from localhost:3000 from your browser.
Can't help you to locate the directory of your Rails application but when you do, just
rails server
If that doesn't work then try following this.
In Environment mode
rails s OR rails server OR rails s -e development
In Production mode
rails s -e production (do not forget to pre-compile your assets before running)
if your platform is jruby then add jruby i.e. jruby -S rails s -e development at the front of the rails command.

Why do I have problems running script/x tasks after installing rails 3 beta?

I installed rails 3 beta in my OSX Leopard. After that, I've created a rails project to test it. From inside its folder, I just can't do script/generate, or even script/server.
It returns '-bash: script/server: No such file or directory'. How could I resolve this issue?
Rails 3 has done away with script/*. Use rails server, rails generate, etc. while in your app's directory.
Run rails --help to get the full list.
In Rails 3, instead of using script/*, use rails. So instead of writing script/generate use rails g (alias of generate) and instead of script/server use rails s (alias of server).
The additional usage of port/environment is the same as in Rails 2. So you can add the port 3005 (default is 3000) with production environment as rails s -p 3005 -e production. Hope that will solve your problem.

Resources