Hello,
I am updating an object with an AJAX form:
view:
<% remote_form_for(@sample, :update => "content2") do %>
<p>
parameter: <br />
<%= select("sample","parameter",Parameter.find(:all).collect {|p|
[p.description.gsub('_', ' '),p.id]},{},{:size => 4, :multiple =>
true}) %>
</p>
<%= submit_tag "add" %>
<% end %>
once form is sent, object is saved in def update in my controller:
controller:
def update
@sample = Sample.find(params[:id])
if @sample.update_attributes(params[:sample])
flash[:notice] = 'Sample was successfully updated.'
redirect_to(@sample)
else
render :action => "edit"
end
end
my problem is that redirect_to(@sample) call the show method via a
HTML request, so all my page is refreshed when the view show.html.erb
is displayed...which is not what i want as i sent the form through
AJAX in order to update the DOM "content2"
Is it possible to change redirect_to so that the call of def show is
done through xmlhttprequest and only my partial _show.html.erb is
displayed (I already have a show.js.rjs)?
I tryied to play with format in update but i always get an argument
error when request is done via AJAX.
def update:
respond_to do |format|
if @sample.update_attributes(params[:sample])
flash[:notice] = 'Sample was successfully updated.'
format.html {redirect_to(@sample)}
format.xml_http_request :get, "show",:id => @sample
else
render :action => "edit"
end
May be i am not using correctly the xml_http_request function.
thank you for your help.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---