Run ruby file in rails console - ruby-on-rails

I've created a file ebm.rb script to add new entries to a database in rails.
The file is very long, and uses some rails models.
Can I easily execute ebm.rb in the rails console?
I tried something with load and require, but that didn't work. My ebm.rb file is located in C:\Sites\ebm and my rails project in C:\Sites\rublesql.

You can run the code in the file in the context of your rails app with
rails runner
http://guides.rubyonrails.org/command_line.html#rails-runner

Related

How can re-create the db file in ruby on rails

When I create an app by rails new I skip the few options which I never used.
rails new backend --api --skip-action-mailer --skip-action-mailbox --skip-active-storage --skip-action-cable --skip-javascript --skip-test --database=postgresql
...but I realized I can not find my .db file. Is this because I skip the test or action-storage? I suddenly think I should not use --skip options if it is not clear idea...
Based on you question it sounds like you have not run rails db:create at the command line yet. You must do this once your Rails project has been created in order to access the database.
Postgres stores data in own folder, only sqlite stores data in your project folder.
For database configuration check config/database.yml

RAILS GENERATE MIGRATION CreateContacts

I am using c9 IDE.
The command I entered in the terminal: bundle exec rails generate migration CreateContacts.
I get a message: error: could not find 'rails'.
This is the command in Nitrous, is there a different command in cloud9?
Is there a step-by-step procedure to manually create the rails migration CreateContacts in the File Directory in cloud9? What code is entered into the newly created files. I notice in the Rails Guide a a file is generated e.g. number (YYYYMMDDHHMMSS)_create_contacts.rb, if this file is manually created will this number e.g. (20160928130510)_create_contacts.rb - be correct and what code is entered into the file?
I'm pretty stuck here and need some expert guidance on this one please.
I use cloud9 IDE as well and when i want to create a migration file i simply do rails generate migration . (I dont include bundle exec in the command)
The file generated in the migration folder will be created in the YYYYMMDDHHMMSS format.

How to generate migration inside folder db/migrate on a personal engine of Rails

I think the title is very clear about what I need. The structure of the engine is not like a Rails application. I need to know what lib I require to use the command:
rails g migration ...
Inside folder of my personal engine
I would simply generate the migration within your rails directory and move it to the engine. This will generate the time-stamp and class, and it doesn't need to stay in the /db/migrate folder of your rails directory.

Run rails application without using rails console or run rails application directly from Batch file

I am working on Ruby on Rails application. For some reason I want to start my application from a batch file. Using the bat file I successfully run rails server and rails console. But I can't send the command from my batch file to rails console to start the application itself. Is there possibility to run rails console from batch file with key (something like: rails c & 'key running application') or is there any possibility to start the application directly from batch file without starting rails console? Thanks in advance!
In batch file write:
call rails c %*
or
call rails s %*
Anything you pass to batch file will be forwarded to rails commands. e.g.
start_console.bat foo bar, will results in rails c foo bar

cannot run rails server command for already created project

I have got an application which was zipped and I unzipped the files and it gave me a folder with all the required structure of a rails application. But when I am going inside the directory and running the rails server command, its not doing anything, but showing me the list of options rails command can do. What would have been the problem?
thanks
Maybe this will help from app folder try:
ruby script/rails server
As explained by Dave Isaacs, Showing the list of options is what the rails command does when it is executed outside the context of an application (i.e., not in the application directories).
Type the full command, including the /script path to the CLI.
script/rails server
instead of
rails server
where script is the path to the rails command that, in a Rails 3 application, lives in the script folder.
I would assume that the application you got was written with rails 2.x. In that case, you have to start it with
script/server

Resources