Editus
Streamline your coding and database editing processes with Editus. Its intuitive web interface allows you to execute code snippets and perform real-time database modifications with ease.
Table of contents
- Editus
- Table of contents
- Installation
- Usage
- Authentication
- Models
- Add Script
- Query
 
 
- Contributing
- License
Table of contents generated with markdown-toc
Installation
Add this line to your application's Gemfile:
gem "editus"And then execute:
$ bundle installRun the following code to create the config file:
rake editus:install # It will create file config/initializer/editus.rbAdd the following to your config/routes.rb:
Rails.application.routes.draw do
  mount Editus::Engine => "/editus" unless Rails.env.production?
  ...
endUsage
Authentication
Editus supports two forms of authentication:
- Define the editus_accountmethod inApplicationHelper: This method should return the current account (e.g.,current_userorcurrent_admin). If this method is defined, Editus will use it to determine the current account.
  module ApplicationHelper
    def editus_account
      current_user # or any other method that returns the current account
    end
  end- Configuration in the config/initializer/editus.rb file: Create an array containing accounts authenticated via HTTP Basic Authentication. Each account is a sub-array with two elements: the username and password.
config.auth = [%w[user@example.com Pass@123456], %w[manager@example.com Pass@123456]]Use one of the above authentication methods to secure access to Editus. Note that the editus_account method will take precedence if both methods are provided.
Models
Display a simple form interface that helps you update the fields of the selected model. The update will use update_columns so will ignore callback and validate
You can configure to display only the models and fields that you allow:
config.models = ["User", {name: "Admin", fields: %w[name], exclude_fields: %w[id]}]
For the Admin model specified using the fields key. Additionally, the exclude_fields key is used to exclude the id field from being displayed.
Add Script
To execute existing code create a directory config/editus in your code
Example:
config/editus/update_nick_name_user.rb
Editus::Script.define :update_nick_name_user do
  title "Update nick_name of user"
  task :up do |id, new_nick_name|
    user = User.find(id)
    old_nick_name = user.nick_name
    user.update_columns nick_name: new_nick_name
    [id, old_nick_name]
  end
  task :down do |id, nick_name|
    User.find(id).update_columns(nick_name: nick_name)
  end
endMake sure the filename and the defined name are the same. In the above code title to set the title of the code.
task :up is the code that will be executed when you run it.
task :down is the code that will be executed when you undo, if you don't need to undo you can skip it.
It can use the result returned from the up method to use as an input parameter. The up method can also accept parameters directly.
Query
In addition to running the two tasks up and down, you can perform other small code snippets by using query.
Editus::Script.define :users do
  desc "Number of users"
  query :count_user do
    User.count
  end
endContributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.