I’m having a problem with an AJAX form. I currently have a working
version as follows:
In my _picker.rhtml partial I have:
<%= observe_form “picker_form”, :update => “frame_picker” ,
:loading_text => “Retrieving price…”,
:complete => visual_effect(:highlight,
“picker_live_price”, { :startcolor => “’#9b3801’”, :endcolor =>
“’#f0c18e’”, :duration => 0.5 }),
:url => { :controller => ‘store’,
:action => “update_picker” } %>
In my store_controller.rb controller I have:
def update_picker
@frame = Frame.find(:first, :conditions => [“category = :category”,
params[:frame]])
@quantity = params[:picker_quantity]
render :partial => ‘/store/picker’
end
If I inspect the params array in the controller, it looks like:
{“action” => “update_picker”, “frame” => {…}, “controller” => “store”}
This is all good and it works. However, for some usability reasons, I
want to change this to use RJS. So, I’ve done the following:
In the partial, I removed the :update and :complete pieces of the
observe_form call that will now be handled by the rjs template:
<%= observe_form “picker_form” :loading_text => “Retrieving price…”,
:url => { :controller => ‘store’, :action
=> “update_picker” } %>
In the controller, I removed the render call:
def update_picker
@frame = Frame.find(:first, :conditions => [“category = :category”,
params[:frame]])
@quantity = params[:picker_quantity]
end
I added the update_picker.rjs rjs template:
page[:frame_picker].replace_html :partial => ‘picker’
page[:picker_live_price].visual_effect :highlight, :startcolor =>
“’#9b3801’”, :endcolor => “’#f0c18e’”
This does not work - I get an error on the Frame.find line in the
controller’s ‘update_picker’ action, because params[:frame] is nil. If I
inspect the params array, it looks like: {“action” => “update_picker”,
“controller” => “store”}. Notice that the frame key and values are no
longer there.
So, the problem appears to be that the form values are not getting
passed through from the observe_form command to the controller in this
second version. What have I done to account for the observe_form command
changing what it is passing through to the controller?
NOTE: The first field in my form is a radio button - does that make any kind of difference?
I would appreciate any help.
thanks.