ruby-on-rails-3prototypejsruby-on-rails-2updatingrjs

rails observe_form and prototype: return '$A($(form).getElementsByTagName('*'))'


I have observe_form in my view: <%= observe_form 'new_lead', :url => { :action => 'update_price' }, :frequency => 0.1 %> , _update_price.rjs partial and this method in controller:



      def update_price
        unless request.xhr?
          redirect_to :controller => 'index'
        else
          set_price_group

          render :partial => "update_price", 
                 :locals  => { :services => params[:service], 
                               :spectr   => params[:spectr]   }
        end
      end

I'm upgrading rails_2 app to rails_3. On rails_2 it's no errors, but when I upgrade project to rails3 I have javascript error in 3484 line of prototype.js: "$(...).getElementsByTagName is not a function ".



       getElements: function(form) {
        return $A($(form).getElementsByTagName('*')).inject([],
        function(elements, child) {
          if (Form.Element.Serializers[child.tagName.toLowerCase()])
            elements.push(Element.extend(child));
          return elements;
        }
       );}, 

And 'update_price' does not calling periodically. I don't know is it problem related to rails upgrading or just problem with JS :( How can I fix this problem?


Solution

  • Rails 3.1 uses jQuery instead of Prototypejs. You can get back the prototype functionality by using something like https://github.com/rails/prototype-rails

    Related How to swap jquery for prototype in Rails 3.1