Thursday 8 August 2013

How to properly call a helper method or js.rjs file from JQuery? [Rails 2.3.11]

How to properly call a helper method or js.rjs file from JQuery? [Rails
2.3.11]

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.

No comments:

Post a Comment