# trouble with remote\_form\_for & html\_update

**URL:** <https://discuss.rubyonrails.org/t/trouble-with-remote-form-for-html-update/53231>\
**Category:** rubyonrails-talk\
**Created:** [July 27, 2010, 7:56pm UTC](https://discuss.rubyonrails.org/t/trouble-with-remote-form-for-html-update/53231 "2010-07-27T19:56:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [July 27, 2010, 7:56pm UTC](https://discuss.rubyonrails.org/t/trouble-with-remote-form-for-html-update/53231/1 "2010-07-27T19:56:27Z")

</div>

I have a form that accepts comments and adds them to a list without refreshing the page.

This is the html:

\<div id='aremark'\> \<%= render :partial =\> 'comment' %\> \</div\>

&nbsp;&nbsp;\<% remote\_form\_for :comment, :url=\>story\_comments\_path(@story), :html =\> { :id =\> 'comment' } do |form| %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<h5\>\<label for="login"\>Make a comment:\</label\>\</h5\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<div id="body"\>\<%= form.text\_field :body %\>\</div\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<p\>\<%= submit\_tag 'Comment' %\>\</p\>

&nbsp;&nbsp;\<% end %\>

The form works i.e on refreshing the page the new comment is seen in the comment partial.

From comments\_controller

def create &nbsp;&nbsp;&nbsp;&nbsp;@story = Story.find(params[:story\_id]) &nbsp;&nbsp;&nbsp;&nbsp;@story.comments.create params[:comment] &nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = "Thank you for commenting" end

This is create.rjs

\<script\> aremark = page.getElementById("aremark") page.replace\_html('aremark', :partial =\> "content") \</script\>

This was working then didn't. I don't know what I did to break it. Can anybody see where I am going wrong?

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [July 27, 2010, 8:02pm UTC](https://discuss.rubyonrails.org/t/trouble-with-remote-form-for-html-update/53231/2 "2010-07-27T20:02:48Z")

</div>

Neil Bye wrote:

> I have a form that accepts comments and adds them to a list without refreshing the page.

It should read

I want a form that accepts comments and adds them to a list without refreshing the page.

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [July 27, 2010, 9:13pm UTC](https://discuss.rubyonrails.org/t/trouble-with-remote-form-for-html-update/53231/3 "2010-07-27T21:13:42Z")

</div>

> This is create.rjs
> 
> \<script\> aremark = page.getElementById("aremark") page.replace\_html('aremark', :partial =\> "content") \</script\>

This is weird - if it's an rjs file you don't want script tags - an rjs file only contains ruby.

Fred

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [July 27, 2010, 10:35pm UTC](https://discuss.rubyonrails.org/t/trouble-with-remote-form-for-html-update/53231/4 "2010-07-27T22:35:35Z")

</div>

So I strip it down to

page.replace\_html('aremark', :partial =\> "content")

Still won't work without refreshing the page

Frederick Cheung wrote:

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [July 28, 2010, 12:44pm UTC](https://discuss.rubyonrails.org/t/trouble-with-remote-form-for-html-update/53231/5 "2010-07-28T12:44:29Z")

</div>

In the log I get

ActionView::MissingTemplate (Missing template comments/create.erb in view path app/views):

Does that help anyone to explain

---

<div class="post-metadata">

**Author:** ![Oldroy](https://avatars.discourse-cdn.com/v4/letter/o/f08c70/32.png) [@Oldroy](https://discuss.rubyonrails.org/u/Oldroy)\
**Post date:** [July 28, 2010, 2:56pm UTC](https://discuss.rubyonrails.org/t/trouble-with-remote-form-for-html-update/53231/6 "2010-07-28T14:56:51Z")

</div>

Hello, Shouldn't you be doing page.replace\_html from inside your controller and using your rjs page as a paramater passed to page.replace\_html??

I think the log is telling you that your request found def create....but without making def create render something other than create.html.erb, won't the controller be looking for that instead of your rjs template?

Oldroy

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [July 28, 2010, 4:43pm UTC](https://discuss.rubyonrails.org/t/trouble-with-remote-form-for-html-update/53231/7 "2010-07-28T16:43:19Z")

</div>

Oldroy wrote:

> Hello, Shouldn't you be doing page.replace\_html from inside your controller and using your rjs page as a paramater passed to page.replace\_html??

I don't understand, how would it find the rjs and if the page.replace\_htm is in the controller what would it contain?

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [July 28, 2010, 5:02pm UTC](https://discuss.rubyonrails.org/t/trouble-with-remote-form-for-html-update/53231/8 "2010-07-28T17:02:30Z")

</div>

Neil Bye wrote:

> Oldroy wrote:

but without making def create render something other than create.html.erb, won't the controller be looking for that instead of your rjs template?

I think this is the problem but I don't know the solution. Surely in the absence of create.html.erb it should find create.rjs but doesn't???
