# RJS problem after upgrading to Rails 2.0.2

**URL:** <https://www.ruby-forum.com/t/rjs-problem-after-upgrading-to-rails-2-0-2/152086>\
**Category:** Rails\
**Created:** [October 30, 2008, 12:14am UTC](https://www.ruby-forum.com/t/rjs-problem-after-upgrading-to-rails-2-0-2/152086 "2008-10-30T00:14:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [October 30, 2008, 12:14am UTC](https://www.ruby-forum.com/t/rjs-problem-after-upgrading-to-rails-2-0-2/152086/1 "2008-10-30T00:14:43Z")

</div>

I just updated an old app from 1.2.6 to 2.0.2 and I’m having an rjs  
problem.  
I have one page that has 2 submit to remote buttons, one to do a price  
override and the other to remove the lineitem. Everything is working  
perfectly before the update but now the price override doesn’t update  
the  
page. I’ve verified that the price\_override method still gets called  
because the price in the session is successfully updated. I even tried  
deleting everything out of the price\_override.rjs and just leaving  
page.alert “test”. Nothing happens and I have no idea why. Can someone  
point me in the right direction?  
sale\_controller.rb

def auto\_remove\_contract  
@contract\_lines = []  
@contract\_lines = session[:contract\_lines] unless  
session[:contract\_lines].nil?  
@contract\_lines.delete\_at(params[:contract\_index].to\_i)  
session[:contract\_lines] = @contract\_lines  
calculate\_totals  
respond\_to do |format|  
format.js  
end  
end

def price\_override  
if request.post?  
@type = params[:type]  
@price = params[:price]  
@index = params[:index]  
unless params[:price].blank?  
if params[:type] == ‘lineitem’  
session[:lineitems][params[:index].to\_i][1] =  
params[:price].to\_f  
unless session[:lineitems].nil?  
elsif params[:type] == ‘contract’  
session[:contract\_lines][params[:index].to\_i][5] =  
params[:price].to\_f unless session[:contract\_lines].nil?  
else  
flash[:error] = “There was a problem completing your request,  
‘Missing type’.”  
end  
else  
flash[:error] = “Please enter a valid amount.”  
end  
end  
calculate\_totals  
respond\_to do |format|  
format.js  
end  
end

new.rhtml

\<% form\_tag do %\>  
\<%= hidden\_field\_tag :index, current\_contracts\_counter %\>  
\<%= hidden\_field\_tag :type, ‘contract’ %\>  
\<%= text\_field\_tag :price, “”, { :id =\>  
“contract\_price\_override\_#{current\_contracts\_counter}” } %\>  
\<%= submit\_to\_remote(‘update\_contract’, ‘Update’, :url =\> {  
:action  
=\> ‘price\_override’ }, :html =\> {:style =\> “width:60px;”}) %\>  
\<%= hidden\_field\_tag :contract\_index,  
current\_contracts\_counter %\>  
\<%= submit\_to\_remote(‘remove\_contract’, ‘Remove’, :url =\> {  
:action  
=\> ‘auto\_remove\_contract’}, :html =\> {:style =\> “width:60px;”}) %\>  
\<% end %\>

price\_override.rjs

page \<\<  
“document.getElementById(‘#{@type}_price\_override_#{@index}’).value  
= ‘’;”  
if flash[:error].blank?  
page.replace\_html “#{@type}_price_#{@index}”,  
number\_to\_currency(@price.to\_f)  
page.visual\_effect :highlight, “#{@type}_price_#{@index}”  
page.replace\_html :current\_totals, :partial =\> ‘current\_totals’  
page.visual\_effect :highlight, :current\_totals  
else  
page.replace\_html “#{@type}_price_#{@index}”,  
“#{number\_to\_currency(@price.to\_f)}&nbsp;#{flash[:error]}”  
flash.discard  
end

auto\_remove\_contract.rjs

if flash[:error].blank?  
page.replace\_html :current\_contracts, :partial =\> ‘current\_contracts’,  
:collection =\> @contract\_lines  
page.visual\_effect :highlight, :current\_contracts\_holder  
page.replace\_html :current\_totals, :partial =\> ‘current\_totals’  
page.visual\_effect :highlight, :current\_totals  
else  
page.alert flash[:error]  
flash.discard  
end

Chris B.  
[http://www.randomutterings.com](http://www.randomutterings.com)
