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 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Do the logs show that the server is being hit? If not, make sure the right .js files are included. swanand deodhar wrote:> > 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 > > > > >-- 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. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 : <head> ... <%= javascript_include_tag :defaults %> ... </head> 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 => ''<p id="count">''+params[:name].length.to_s+''</p>'' end end View: <p id="count">0</p> <% 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 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Hey guys!! Thnx a lot. Tht worked like a treat.. Thnx and regards, Swanand On 1/23/07, "Sébastien Grosjean (ZenCocoon)" <public-pF6qlRHTujOaMJb+Lgu22Q@public.gmane.org> wrote:> > > 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 : > > <head> > ... > <%= javascript_include_tag :defaults %> > ... > </head> > > 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 => ''<p id="count">''+params[:name].length.to_s+''</p>'' > end > end > > > View: > > <p id="count">0</p> > <% 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 > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---