简体   繁体   中英

Rails console access through web page interface?

This is a bit of an odd request and not certain on how to approach it, but essentially we want an admin portal where devs can access a Rails-type console directly.

Ideally, we'd be able to paste something like this:

count = User.count

puts "We have #{count} users!!"

and have it output:

We have 872633 users!!

Obviously the commands would be more extensive than that, as they could be exporting, making direct updates, etc. The more info we can have outputted the better, such as DEBUG logs, SQL queries, etc, just not sure on how to get access to something like that.

We recognize it's not great practice, but time and time again we need something from the console directly, and we'd like to be able to submit the proposal, require another dev to verify/approve it, and then keep a log of the commands run.

Is there a gem out there that handles this? If not, are there any recommendations on how to implement something like this?

You can use web-console gem in production and run console in admin space, like:

class AdminController < ApplicationController
  def console_page
    console
    render inline: '<h2>console page</h2>'
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM