I am running Rails 3.0.7 with Ruby 1.9.2 and using jquery. I ran
$ rails generate jquery:install
to get the right javascript files for AJAX.
HTML:
<%= javascript_include_tag :all %>
...
<div id="time_div">
I don''t have the time, but
<%= link_to( "click here", :action=>
''say_when'', :remote =>
true, :format => :js ) %>
and I will look it up.
</div>
say_when.js.rjs:
page.replace :time_div, "<p>The time is <b>
#{DateTime.now.to_s} </b></
p>"
When I click on the link, instead of replacing the div html, the
entire page is replaced with the generated javascript:
try {
Element.replace("time_div", "<p>The time is <b>
2012-04-11T16:43:23-04:00 </b></p>");
} catch (e) { alert(''RJS error:\n\n'' + e.toString());
alert(''Element.replace(\"time_div\", \"<p>The time
is <b>
2012-04-11T16:43:23-04:00 </b></p>\");''); throw e }
page.replace_html does the same thing.
What am I doing wrong?
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Solved my own problem. The link_to should be:
<%= link_to( "click here", {:action=>
''say_when'', :format
=> :js}, :remote => true, :method => :post ) %>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
I also had to replace say_when.js.rjs with
say_when.js.erb:
$(''#time_div'').html(''<p>The time is <b>
<%= DateTime.now.to_s %> </b></
p>'')
On Apr 12, 11:47 am, jsnark <s...-I/mPKdbEGRBWk0Htik3J/w@public.gmane.org>
wrote:> Solved my own problem. The link_to should be:
>
> <%= link_to( "click here", {:action=>
''say_when'', :format
> => :js}, :remote => true, :method => :post ) %>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.