Speeding up rails development deployment - ruby-on-rails

I got a rails app that requires redis, mongod, and postgres before starting with rails s. I do not like open several tabs on my terminal and open these services one by one. Is there a way to run everything with one command/script? Is there a specific gem that might help with this? Thanks.

one way is mentioned by #Tres with using the foreman gem. If you are using rvm you can use a .rvmrc file in your project. There you can simply define some shell commands like
mongod --port 23017
postgresql start
and the like ...

Related

Start postgresql db every time using rails server?

I'm trying to locally start my rails server
but do I have to start my postgresql db each time I want to rails s?
I'm new to rails so I'm not sure how this works. I remember not having to do such a thing on something I've worked on before..
As mentioned in other answers you have to make sure that Postgres is runnign and serving your database. This is not handled by Rails.
Usually you would configure the Postgres server as an OS background service that starts with your system. Which operating system do you use? In case it's MacOS and you're already using Homebrew, I'd recommend using Hombrew services. You can read more about it here: https://github.com/Homebrew/homebrew-services
Basically you'd tell Homebrew to start postgres with your system, like this: brew services start postgres
You can use system commands to run postgresql server automatically on system boot
sudo systemctl enable postgresql
or
sudo update-rc.d postgresql enable
However it also belongs on how you install postgres

running rails console in Capistrano deployed app

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

Force start Rails application through foreman only

I am using foreman in my Rails application and all works fine when I run foreman start but sometime I forget it and run only Rails application as rails s. Then I spend some time trying to investigate problems related to not working services (like sidekiq).
So, can somebody recommend a way how to force starting my application through foreman only? In other cases I want to see error message.
You could add an environment variable to .env, which is read when Foreman starts, and then check for its presence in a Rails initializer.

Rails commands not working properly

I couldn't find anyone else with this problem so I thought I'd ask.
rails new myNewRailsApp
This works fine.
cd myNewRailsApp
ls
Reveals everything seems to have generated properly.
rails server
This creates a new directory "server" and creates a new rails application. It also seems to happen with "generate" and other command words. I'm on version 3.0.9 (considering rolling back now), and I purged it, all gems, and reinstalled. Am I missing something obvious?
Edit: I'm running on Ubuntu 11.04.
Looks as though it's using Rails 2 to generate a new app within your app. I've done this a few times and the amount of apps I've created with app names of "c" and "s".
To get round either use
bundle exec rails server
or
script/rails server
Or uninstall rails 2 from your system
Seems like the command is still using 2.x version of rails.
If you want to use multiple versions of rails for different projects use rvm to create gemset for each rails version.
[http://beginrescueend.com/][1]
If you dont want to use rvm, uninstall older versions of rails and try re-installing rails 3.x.

Rails Server Command

I am new to Ruby on Rails and am following a tutorial to create a class project.
I can generate a new rails project with
$ rails project
The problem Im having is when I try to start my server, It will generate a project called server:
$ rails server
or
$ rails s
I figured out that I need to install/update rails to 3.0.3 to use this command every time I open terminal. I find myself having to install gems(bundle, etc) every time I need to work on my project.
Is there anyway to save this terminal session or profile for later use?
Is it user error?
Im new to Rails and about the same with terminal.
Any help would be greatly appreciated. I have resorted to leaving my computer and terminal open for about a week...
Welcome on board! - You'll have fun, I found setting up the environment the most difficult thing.
in rails 2 you start the server with ruby script/server.
to upgrade to rails 3 try gem install rails -v=3.0.4
I put the version but it's not a mandatory option.
To uninstall a gem (as rails is) is gem uninstall gemname -v=x.x.x. -
gem list will tell you the version of each gem.
I hope you've got rvm, if not I strongly sugget you to install it, this will allow you not only to use different versions of ruby but also to set different gemsets, therefor one each project, you'll find it useful.
Once in rails 3 you can use bundler, have a look at this episode of railscasts, by the way this is a very good site, but you may know it already.
another edit...
I don't know the behavior you're describing, looks like something is wrong with your environment, but I need to know if you have rvm to solve this, if so try rvm list and rvm gemset, With the first you get the list of installed ruby, you can switch between them with rvm 1.9.2 i.e. and rvm 1.9.2#gemdirname with the gemdir coming from the second list. You should find your configuration in one of those list.
Hi if you are using rails 2.8 or lesser use this to start the server
ruby script/server
rails new project is for new rails project n rails s is for starting server

Resources