Hi!
I want to do a functionality of wordcount. I thought of using
observers
for doing that. I attached an observer to the textarea and set the
polling
time as 1 second. Then in the controller i wrote the method called
counter
which will take the raw_post and will count the words using length
or something like that
But my problem is in the observer it is not doing the updations.
Here is my observer code:
<%= observe_field (:value,
:frequency=>0.5,
:update=>‘count’,
:url=>{:action=>:counter}) %>
What could be the problem. Plz help.
Thnx and Regards,
Swanand
Do the logs show that the server is being hit? If not, make sure the
right
.js files are included.
swanand deodhar wrote:
:frequency=>0.5, :update=>'count', :url=>{:action=>:counter}) %>
What could be the problem. Plz help.
Thnx and Regards,
Swanand
–
View this message in context:
http://www.nabble.com/-Rails--Observers-tf3062423.html#a8516360
Sent from the RubyOnRails Users mailing list archive at Nabble.com.
Hi
swanand deodhar wrote:
Hi!
I want to do a functionality of wordcount. I thought of using
observers for doing that.
I think a better way for this specific wish would be to do it only in
Javascript to don’t make any request when you don’t need.
After if you like to control the text_area content on server side here
is a way to do it.
I attached an observer to the textarea and set
the polling time as 1 second. Then in the controller i wrote the method
called counter which will take the raw_post and will count the words
using length
or something like that
But my problem is in the observer it is not doing the updations.
Here is my observer code:
<%= observe_field (:value,
:frequency=>0.5,
:update=>‘count’,
:url=>{:action=>:counter}) %>
First things, be sure to have prototype library include.
In your layout you can have :
... <%= javascript_include_tag :defaults %> ...once this is done, here is an working example of controller, view:
Controller:
class ItemsController < ApplicationController
def index
@item = Item.new
end
…
def counter
render :text => ‘
’+params[:name].length.to_s+‘
’end
end
View:
0
<% form_for :item, :url => {:action => :create} do |f| %> <%= f.text_area :name %> <%= observe_field (:item_name, :frequency => 0.5, :update => 'count', :with => 'name', :url=>{:action=>:counter}) %> <% end %>Hope this help
Sébastien Grosjean - ZenCocoon
seb.box.re zencocoon.com
Hey guys!!
Thnx a lot. Tht worked like a treat…
Thnx and regards,
Swanand