rails-console
v0.2.0
Published
Rails interface in Node.js via Rails console
Downloads
5
Readme
rails-console.js
Rails interface in Node.js via Rails console
⚙ Install
# npm
npm i rails-console
# yarn
yarn add rails-console
🔍 Usage
const { RailsConsole } = require('rails-console');
async run() {
const rc = new RailsConsole();
// Or:
const rcWithOptions = new RailsConsole({
cwd: path.resolve(__dirname, 'rails-app'), // Optionally specify directory where to start rails console
});
// Wait for the rails console process to start
await rc.start();
// Get application name
const result = await rc.send('Rails.application.engine_name.gsub(/_application$/,"")');
if (result.success) {
console.log(`Name of the Rails app: ${result.returnValue}`);
} else {
console.log(`Command returned an error: ${result.error}`);
}
if (result.raw.stderr) {
console.log(`Command output warnings: ${result.raw.stderr}`);
}
// Update an ActiveRecord item
await rc.send('User.find(1).update(name: "First User")');
// Stop the process
rc.stop();
}
️❤️ Contributing
Every contribution is really welcome!
If you feel that something can be improved or should be fixed, feel free to open an issue with the feature or the bug found.
If you want to fork and open a pull request (adding features or fixes), feel free to do it.
Read the contributing guidelines
📃 Licence
Read the licence