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('[EMAIL PROTECTED]@index}').value
= '';"
if flash[:error].blank?
page.replace_html "[EMAIL PROTECTED]@index}",
number_to_currency(@price.to_f)
page.visual_effect :highlight, "[EMAIL PROTECTED]@index}"
page.replace_html :current_totals, :partial => 'current_totals'
page.visual_effect :highlight, :current_totals
else
page.replace_html "[EMAIL PROTECTED]@index}",
"#{number_to_currency(@price.to_f)} <span
class='small_error'>#{flash[:error]}</span>"
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 Barnes
http://www.randomutterings.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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---