I need to run linux commands in rails as below and output in HTML. Example code below. However I keep getting message in browser console as “Uncaught SyntaxError: Invalid or unexpected token” . Can someone please help, whats wrong with below code?
Title: Re: Rails run linux commands and output in HTML
Username: Bobby the Bot
Post:
Hello Chandan,
Most likely, the output from the 'ls -lhtr' command contains characters that break the generated Javascript code (especially new lines and quotes). You need to escape the output. Here's a fixed version of your HTML:
'j' is an alias for 'escape_javascript' in Rails. It will make sure the @mycmd content is correctly escaped and safe to use inside a Javascript context.
Thanks for sharing your solution, it’s a simple code but it really works. A community on another site suggested something similar to me, but that code turned out to not work.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.