0

Currently when I click a button a dialog pops up http://jsfiddle.net/RBKaZ/ .

The view of interest with is an html.erb is shown below

<div style="text-align: left;">
<div id="dialog">
    <p>My Heading</p>
    <textarea id="name"></textarea>
  </form>
</div>
....
<%= submit_tag 'My Button',
    :id => 'open' %>

I have the following in my application.html.erb (wrapper for views)

<%= javascript_include_tag 'jquery-1.9.1' %>
<%= javascript_include_tag 'jquery-ui-1.9.2' %>
<%= javascript_include_tag 'popup' %>

When I click 'My Button' ideally I would like to get the value from a method within my app/helpers/application_helper.rb file, then alert this value. Alternatively I would like to call a js.rjs fie located in app/views/toolbox/ which then calls the appropriate helper method.

I have tried doing some sort of alert within js.rjs, but I get a html page with try, catch statements with the appropriate content inside. Could be because I also have <%= javascript_include_tag :defaults %> defined. (I called this file in a way that I know is very wrong).

I'm very new to front end development, and from what I've been searching I probably need to make an ajax call. Haven't been able to find an example that suits my needs, help would be very much appreciated.

Let me know if more information is needed.

1 Answer 1

0

There is no way to call a ruby method from javascript.
Javascript runs in the browser on the client side, ruby is executed on the server.

What you can do, is store the (static) result of a helper in a js variable, or call a controller action via AJAX serving dynamic content.
The later is facilitated with rails 'remote' attribute, see the Rails Guide

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.