Is it possible to run rails console commands in ruby controller/view and display the output -
example want create dropdown of commands in admin section. when user selects one, such
purchase.all user.where(:active => 1)
basically common commands run in console before functional backend created. know bit unconventional im looking rapid way make common admin queries available. once command has been run i'd display exact output displayed in rails console. i've installed hirb gem formats results in console , formatting show when output in view. @ achievable?
of course possible, run command in action, render hirb , pass output view:
def action result = run_command(params[:command]) hirb::view.load_config hirb::view.render_method = lambda { |output| @hirb_output = output } hirb::view.render_output(result) end private def run_command(command) case command when 'purchase_all' purchase.all when 'active_users' user.where(:active => 1) end end
and in view:
<pre> <%= @hirb_output %> </pre>
however, use activeadmin or railsadmin instead.
Comments
Post a Comment