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).
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
So starting from Rails 4.1.x there seems to be a recommended way to use rails under the application folder. Instead of the traditional:
rails server
it is recommended by Rails official guide to use
bin/rails server
It looks like the bin/rails is referencing rails with additional stuff. What would be the additional benefits of using bin/rails compared to rails?
A second question is - I was used to use rails server, rails console, etc. rather than bin/rails server, bin/rails console. Without using bin/rails, would I lose anything (like misloading some libs, etc.)?
Thanks.
Put the following line in your bin/rails file: puts "In the bin/rails file"
Now run rails server. You'll likely see that the rails command is executing the bin/rails file.
I'm guessing the official guide suggests using bin/rails for two reasons:
Avoid using another instance of rails if your paths are not set up properly.
Speed - bin/rails seems to be a bit faster than just rails
Im following a rails tutorial, and when im supposed to run the command: 'bin/rails generate model Article'. An error occurs saying that there isnt such a command.
I'm using 'command prompt with ruby on rails' and in the rails project i can find a Bin folder. Am also using windows 7.
Also What is the difference between running only 'rails generate' instead of running 'bin/rails generate'?
Using rails generate is fine if you have no bin stubs (binaries in the root /bin folder of your project). If you do have bin stubs then it's preferred to use them because they may do additional things specific to your project. But even then, it's (probably) fine to just use rails generate still. The other bin stubs may be a little more necessary to use, though (again, if present) because they tend to be shortcuts to e.g. bundle exec rake.
Rails 4.1 ships with bin stubs. That is, when you generate a Rails 4.1 project it generates bin stubs for you. So this is probably why your tutorial mentioned using them -- they're now there by default. But if you're on an older version of Rails that won't help you much.
The big reason Rails 4.1 includes bin stubs is because Rails uses spring by default now. Spring is an application preloader... that makes it so that when you call e.g. bin/rake ... it will load and keep a running rails environment in the background and then, the 2nd time you call bin/rake it will fork from the running environment giving you almost instantaneous response. So this is an example of "additional things specific to your project" that you get from using bin/rake over just rake and bin/rails over just rails.
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
I am looking at rails plugins to help me modularize my application. I have some basic questions that I am confused about.
Can a rails plugin have its own DB? My application is very little traffic, for internal use, so I am fine with the idea of separate sqlite DB's for each plugin. When I do a "rails plugin new" even if I use --full, there is no database.yml generated. If I create one and do a rake db:create, no sqlite db is created.
Is there a good tutorial available for creating a rails plugin with rails 3.2? Most I find are older and use the enginex gem which I think is now built into rails.
Can you run your plugin as a standalone app for testing, i.e. using WEBrick? When I run "rails server" in my plugin directory, it just says "Error: Command not recognized".
I guess that's it, I am just confused on how to begin.
Creating Migrations
The Rails Guide "Getting Started with Engines" instructs you to use 'rails g model post' from the root directory for your engine.
Getting Started with Engines
If you do this, it will create the db/migrate folder for you with the migration inside of it.
$ rails g model post
invoke active_record
create db/migrate/20120517184738_create_my_engine_posts.rb
create app/models/my_engine/post.rb
invoke test_unit
create test/unit/my_engine/post_test.rb
create test/fixtures/my_engine/posts.yml
You can also generate migrations directly just the same, just as you do with a Rails app.
$ rails g migration AddMyEngineTable
invoke active_record
create db/migrate/20120517185241_add_my_engine_table.rb
Running Rails Server
The Rails Guide also states to run 'rails s' from test/dummy, not from the root of your engine directory.
I see that from an ASCIICast on the subject which covered Rails 3.1 RC5 that you used to be able to run 'rails s' from the root directory of your engine/gem. This is no longer the case.
From the Rails issue posted on Github three months ago it appears that they needed to keep the scope of the engine separate from the scope of the dummy app.
Issue #4894: Mountable Engines Rails File
In short run from the engine root:
test/dummy/script/rails s