Ajax/Controller Problem

Hello,

I am trying to make a category selection for an upload file so that a category can be selected according to the file being uploaded. The model and upload is set up and I am able to select a category from upload.

The problem is: I am making an ‘add a category’ form handled by ajax from the upload view. From the set up I have given below, I am able to add a category but can’t retrieve a selection field through Ajax. It gets added upon refresh. Please review the setup below:

In upload/new.rhtml view:

Upload form (excerpt):

<%= render :partial => 'categories/select' %>

<%= submit_tag :Create %>

<% end -%>

Add category: <%= form_remote_tag :url => {
:action => ‘create_ajax’,
:controller => ‘categories’},

                  :loading => "new Effect.Appear('indicator', { duration: .3 })",
                  :complete => "new Effect.Fade('indicator', { duration: .3 })",
                  :html => {

                  :id => "category_ajax_form"} %>
                  <%= text_field "category", "title" %>
            <%= submit_tag :Create %>

In categories/_select.rhtml partial:

<%= collection_select(“category”, @category, Category.find(:all), “id”, “title”) %>

And lastly, in controller, categories_controller.rb

def create_ajax
@category = Category.new(params[:category])
if @category.save
replace_html render_partial ‘categories/select’
else
render category_path(@post), :layout => false

end

end

Thanks in advance. I am sure there is a way out.

Rizwan

I managed to finally solved this. I called an RJS view from the controller with insert_html :bottom.