# Noob question; remote\_form\_for

**URL:** <https://www.ruby-forum.com/t/noob-question-remote-form-for/140423>\
**Category:** Rails\
**Created:** [June 13, 2008, 7:23pm UTC](https://www.ruby-forum.com/t/noob-question-remote-form-for/140423 "2008-06-13T19:23:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ANSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@ANSS](https://www.ruby-forum.com/u/ANSS)\
**Post date:** [June 13, 2008, 7:23pm UTC](https://www.ruby-forum.com/t/noob-question-remote-form-for/140423/1 "2008-06-13T19:23:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ANSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@ANSS](https://www.ruby-forum.com/u/ANSS)\
**Post date:** [June 13, 2008, 8:28pm UTC](https://www.ruby-forum.com/t/noob-question-remote-form-for/140423/2 "2008-06-13T20:28:22Z")

</div>

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|

---

<div class="post-metadata">

**Author:** ![ANSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@ANSS](https://www.ruby-forum.com/u/ANSS)\
**Post date:** [June 14, 2008, 11:28am UTC](https://www.ruby-forum.com/t/noob-question-remote-form-for/140423/3 "2008-06-14T11:28:22Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> :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](http://www.anasonline.net)

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

---

<div class="post-metadata">

**Author:** ![ANSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@ANSS](https://www.ruby-forum.com/u/ANSS)\
**Post date:** [June 14, 2008, 12:05pm UTC](https://www.ruby-forum.com/t/noob-question-remote-form-for/140423/4 "2008-06-14T12:05:58Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 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](http://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](http://www.anasonline.net)

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