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’)”%>

#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

<%end%>

Message

<%= f.text_area :text, :id => 'text', :size => '30x10', :class => 'fieldcell' %>

Sender

<%= f.text_field :sender, :class => 'fieldcell' %>

Number

<%= f.text_field :number, :class => 'fieldcell' %>
<%= f.submit "Send", :class => 'sbutton' %>

#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?

2008/6/13 julian [email protected]:

:loading => “Element.show(‘sending’)”,

the required div, here is the code:
<% remote_form_for :message, @message, :url => ‘messages/create’,

<%= f.text_area :text, :id => 'text', :size => <%= f.text_field :number, :class => 'fieldcell' %></
    format.html

=> :unprocessable_entity }
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

–
Anas Marrawi
Visit me at: www.anasonline.net

If you want to send me encrypted emails. My public key: pub:13427489:17

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 !!!

2008/6/14 AN@S [email protected]:

its never getting to the ‘render :xml’ call in your controller. It’s

                :complete => "Element.hide('loading')" do |f| %>

.
# @numbers_from_file = params[:contact][:file].split(/\n/)

create.html.erb page !!!
Visit me at: www.anasonline.net

If you want to send me encrypted emails. My public key: pub:13427489:17

–
Anas Marrawi
Visit me at: www.anasonline.net

If you want to send me encrypted emails. My public key: pub:13427489:17