I wrote some code for adding a category to a list of categories on a
page, complete with some rjs effects. The code saves the category
alright but does not execute any js. I have to refresh to see any
changes. Here is what I have been using:
def new
@category = Category.new(params[:category])
respond_to do |format|
if @category.save
format.js
render :partial => 'category', :object => @category
end
You can use the :collections parameter to render the list. I don't
see a need for new.js.erb.
Use the :update=> parameter for the form tag to get the browser to
refresh a section of the screen. Put your partial inside a <div> and
pass the id of the <div> to the update parameter.
You can do the highlights etc. as parameters to the form_remote_tag.
Look at the documentation for form_remote_tag.
I wrote some code for adding a category to a list of categories on a
page, complete with some rjs effects. The code saves the category
alright but does not execute any js. I have to refresh to see any
changes. Here is what I have been using:
def new
@category = Category.new(params[:category])
respond_to do |format|
if @category.save
format.js
render :partial => 'category', :object => @category
end
def list
@categories = Category.find(:all)
end
This can't be exactly what's in your controller because it's
syntatically incorrect. But I'd guess that your new.js.erb file is
never exececuted, since you're telling it to render the partial
instead. On top of that it should be called new.js.rjs, not new.js.erb
I finally got it working. Many thanks to Fred and Mukund.
I changed two things: Firstly instead of putting the div id into an
unordered list I made a separate div tag. Secondly I got rid of the
render partial line in the controller.