Noob question; remote_form_for

Hello, My problem is when submitting a form with remote_form_for I got a message that says:"Template is missing

Missing template messages/create.html.erb" so the remote_form_for searches for a template of the create method instead of just updates the required div, here is the code:

Here is the link when I call the form:

<%= link_to_remote "Send new SMS", :url => 'messages/new_sms',                   :loading => "Element.show('loading')", :update => 'msg_form',                   :complete => "Element.hide('loading')"%></p>

#new_sms.html.erb:

<% remote_form_for :message, @message, :url => 'messages/create',                     :loading => "Element.show('sending')", :update => 'messaging_area',                     :complete => "Element.hide('loading')" do |f| %>

#messaging_area is the div that lists sent messages, this div should be updated by Ajax to show the newly-sent message

<table id="new_message_form"> <tr>   <td colspan="2"><p class="labelcell">Message</p> </td>   <td colspan="2"><%= f.text_area :text, :id => 'text', :size => '30x10', :class => 'fieldcell' %></td> </tr>

<tr>   <td colspan="2"><p class="labelcell">Sender</p> </td>   <td colspan="2"> <%= f.text_field :sender, :class => 'fieldcell' %></

</tr> <tr>   <td colspan="2"><p class="labelcell">Number</p> </td>   <td colspan="2"><%= f.text_field :number, :class => 'fieldcell' %></

</tr>

<tr><td><%= f.submit "Send", :class => 'sbutton' %></td></tr>

<%end%>

</table>

#messages_controller:

. . .   def create     @user = User.find(logged_in_user)     @message = Message.new(:text => params[:message][:text],       :sender => params[:message][:sender],       :number => params[:message][:number],       :user_id => logged_in_user.id     )

    respond_to do |format|       @numbers_array = params[:message][:number].split(/\,+\s*|\s+/)       # @numbers_from_file = params[:contact][:file].split(/\n/)

      if @numbers_array.size <= 16         @message.sendsms         @message.save         @new_count = @user.messages_count + @numbers_array.size         @user.update_attribute(:messages_count,@new_count) # flash[:notice] = 'Message was successfully created.'         format.html # format.xml { render :xml => @message, :status => :created, :location => @message }

      elsif         @numbers_array.size > 16         format.html {render :action => "new"}         flash[:notice] = 'More than ur allowed max'       else         format.html { render :action => "new" }         format.xml { render :xml => @message.errors, :status => :unprocessable_entity }

      end

    end

  end . . .

I hope everything is clear, I know this is a silly problem but I've read the documentation available about remote_form_for and did a lot of googling but didn't know what causes the action to look for a create.html.erb page !!!

Your help is highly appreciated.

Regards

Your remote_form_for is not requesting the xml format and therefore its never getting to the 'render :xml' call in your controller. It's trying to do the default render which is to render the erb template which of course doesn't exist.

I think you need your :url option to be :url => 'messages/create.xml'

remote_form_for :message, @message,   :url => 'messages/create.xml',   :loading => "Element.show('sending')",   :update => 'messaging_area',   :complete => "Element.hide('loading')" do |f|

Hi, I don’t think this is related to xml at all, why would I need to render xml?

Any help?

Hi, The problem has been solved I simply added {redirect_to messages_path} for the format.html, but now I have another problem, when submitting the form, the layout is rendered again though I turned all layouts off for Ajax requests !!!