views:

195

answers:

2

So here is my form

<% remote_form_for([:admin, Page.new]) do |f| %>
    <ol>
        <li>
            <%= f.label(:title) %>
            <%= f.text_field(:title) %>
        </li> 
        <li> 
            <%= f.label(:parent_page) %>
            <%= f.select(:parent_page_id, Page.roots.map { |p| [p.title, p.id] }.unshift(["none", nil])) %>
        </li>
    </ol>
    <div class="modal-controls">
        <%= submit_tag("Save") %> or <%= link_to_function("cancel", "R.Pages.hideAdd();") %>
    </div>
<% end %>

And my action

def create
  @page = Page.create(params[:page])
  @languages = Language.all
  @languages.each do |language|
  @page.page_languages.create(:language_id => language.id)
end

For some reason the submitted for does not call the create.js.rjs template, but instead tries to call create.html.erb, do i need some sort of extra setting with the form?

btw i am using rails 2.3.5

+1  A: 

I can't remember the exact default behavior in rails, but have you tried putting a respond_to at the end of your controller action:

respond_to(:html, :js)

Hope this helps.

EDIT

I went back to check on the default behavior for Rails in respect to rendering views. Rails favors convention over configuration in this instance. The default behavior is that Rails automatically renders views with names that correspond to actions. You don't need the respond_to any more if you stick to this convention. Here is the documentation.

Just wanted to update my post with the correct info... glad you figured your problem out.

Ryan Ferretti
+1  A: 

I had named my template create.rjs.js instead of create.js.rjs, thats why i didnt work

hojberg