11175
(-- --)
June 14, 2009, 9:18pm
1
I can't make it work.
<%= text_field_tag :friend %>
<%= observe_field :friend, :url => friendships_url, :on => :click %>
<%= javascript_include_tag :defaults %>
Raises the error:Can't find variable Form.
The generated html is:
<input id="friend" name="friend" type="text" />
<script type="text/javascript">
//<![CDATA[
new Form.Element.EventObserver('friend', function(element, value) {new
Ajax.Request('http://mysite.com/friendships ’, {asynchronous:true,
evalScripts:true, parameters:value + '&authenticity_token=' +
encodeURIComponent('...edited...')})})
//]]>
</script>
The:
<%= javascript_include_tag :defaults %>
Should appear BEFORE the:
<%= observe_field :friend, :url => friendships_url, :on => :click %>
It's usually placed at your page's <header> section.
11175
(-- --)
June 14, 2009, 9:38pm
3
Just to save people 1hr of head banging:
This DOES NOT WORK: (data is submitted to ApplicationController/index!!!
<%= observe_field :friendship_accessibility, :url =>
friendship_url(friendship),
:on => :click, :with => :accessibility %>
This works: (all options are compulsory)
<%= observe_field :friendship_accessibility,
:url => {:controller => 'friendships', :action => 'update', :id =>
friendship},
:on => :click, :with => :accessibility, :method => :update %>
Is that a bug? Why can't the observe_field and Rails routing mechanism
recognize the restful route?
Mukund
(Mukund)
June 15, 2009, 6:04am
4
You don't have an :update specified on the parameters for
observe_field. Assuming you don't want to render anything, do a
render :nothing=>true in the controller.