Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling SH script from RubyOnRails View - Passing arguments and redirecting to an html file on the filesystem afterwards
    text
    copied!<p>New to ruby, i've stumbled into the following issue while trying to execute a SH script from within a view (index.html.erb). I have done the following:</p> <p>app\views\tests\index.html.erb</p> <pre><code>&lt;%= link_to 'Run it', :action=&gt;'callthis' %&gt; </code></pre> <p>app\controllers\tests_controller.rb</p> <pre><code>def callthis puts "I was called!" # system call here end </code></pre> <p>I'm getting the following error</p> <pre><code>ActionController::RoutingError (No route matches {:action=&gt;"callthis", controller=&gt;"tests"}): app/views/tests/index.html.erb:20:in `_app_views_tests_index_html_erb__911976670__617626598' app/views/tests/index.html.erb:4:in `each' app/views/tests/index.html.erb:4:in `_app_views_tests_index_html_erb__911976670__617626598' app/controllers/tests_controller.rb:7:in `index' </code></pre> <p>Edit: Routes</p> <pre><code>tests GET /tests(.:format) tests#index POST /tests(.:format) tests#create new_test GET /tests/new(.:format) tests#new edit_test GET /tests/:id/edit(.:format) tests#edit test GET /tests/:id(.:format) tests#show PUT /tests/:id(.:format) tests#update DELETE /tests/:id(.:format) tests#destroy </code></pre> <p>Edit 2: Thanks Zippy, I see hello is output, however, it also gives me the following error:</p> <pre><code>Hello Started GET "/tests/callthis" for 10.10.9.141 at Wed Mar 13 16:29:22 -0400 2013 Processing by TestsController#callthis as HTML Completed 500 Internal Server Error in 6ms ActionView::MissingTemplate (Missing template tests/callthis, application/callthis with {:handlers=&gt;[:erb, :builde :formats=&gt;[:html], :locale=&gt;[:en]}. Searched in: * "/mnt/wt/ruby/wtrorp/app/views" ): </code></pre> <p>Edit 3:</p> <p>From the 'tests' view, I am only looking to execute the 'callthis' defined in the 'testscontroller'. That def will just be a system call to execute an SH script, and redirect to the output file it generates to the filesystem. I am looking to pass it two args: a string (which is in the test object 'test.script') and an id (which i want to pull from the browser session). I realize the problem just got a lot harder and will update the header question to reflect it :D</p> <pre><code>system(./callthis.sh test.script $my_id_var) </code></pre> <p>Edit 4:</p> <p>I am looking to generate a file from the sh script, and redirect to a static. The static page will catch a variable, and know which file the sh script generated, so that it may display it in a frame of that static page. Maybe out of the context of this question, but can someone point me in the right direction?</p> <p>Thank you in advance for your time!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload