js update partial missing template

PermissionsController   def add_member     ...snip...     @permissions = Permission.all     respond_to do |format|       format.html {         flash[:messages1] = @permission.user.name + " has been given rights."       }       format.js     end   end

app/views/permissions/add_member.js.erb $('#privileges').replaceWith("<%= escape_javascript(render(@permissions)) %>");

view (_permissions.html.erb with some snippage of extraneous things) <div id="privileges">   <div id="messages1" class="round">     <%= flash[:messages1].html_safe %>   </div>     <div class="block" id="users" align="left">       <ul id="priv_users" class="ui-widget-header" align="left">         <% for u in @users -%><li id="moveable-<%= u.id %>" class="ui-widget-content" data-add="<%= u.id %>"><%= u.uid %></li><% end -%>       </ul>     </div>   </div> </div>

<p>Missing template permissions/add_member, application/add_member with {:locale=&gt;[:en, :en], :handlers=&gt;[:coffee, :builder, :erb], :formats=&gt;[:html]}. Searched in:   * &quot;/home/users/cwhite/tti_framework/app/views&quot; </p>

and if I rename app/views/permissions/add_member.js.erb to add_member.erb, I get a different error...

  Showing <i>/home/users/cwhite/tti_framework/app/views/permissions/add_member.erb</i> where line <b>#1</b> raised:   <pre><code>Missing partial permissions/permission with {:locale=&gt;[:en, :en], :handlers=&gt;[:coffee, :builder, :erb], :formats=&gt;[:html]}. Searched in:   * &quot;/home/users/cwhite/tti_framework/app/views&quot; </code></pre>

Been stuck on this for too long now... what obvious thing am I missing?

Hi Craig,

Hi Craig,

<p>Missing template ... :formats=&gt;[:html]}.

That looks like a clue. Have you checked your request header?

Hi Craig,

<p>Missing template ... :formats=&gt;[:html]}.

That looks like a clue. Have you checked your request header?

---- I think so... I've been staring at firebug and even copied the errors out of firebug and this looks like it wants to respond to html and not js and in fact, I enabled it to 'render :partial => "permissions"' and it clearly wants to respond with html and not js.

Then my best advice would be to double check the accepts header using Live Http Headers. You may need to do some explicit setup prior to the post.

Bill

Hi Craig,

<p>Missing template ... :formats=&gt;[:html]}.

That looks like a clue. Have you checked your request header?

---- I think so... I've been staring at firebug and even copied the errors out of firebug and this looks like it wants to respond to html and not js and in fact, I enabled it to 'render :partial => "permissions"' and it clearly wants to respond with html and not js.

Then my best advice would be to double check the accepts header using Live Http Headers. You may need to do some explicit setup prior to the post.

Sorry if my question is not about the main problem but, could you explain why are you using .replaceWith()?

Usually I use $(“#myDiv”).html("<%= escape_javascript(render “partial”, locals)%>

Do you find replaceWith() better than html() ??

Thanks in advance

Javier

app/views/permissions/add_member.js.erb $('#privileges').replaceWith("<%= escape_javascript(render(@permissions)) %>");

Sorry if my question is not about the main problem but, could you explain why are you using .replaceWith()?

Usually I use $("#myDiv").html("<%= escape_javascript(render "partial", locals)%>

Do you find replaceWith() better than html() ??

Thanks in advance

Then my best advice would be to double check the accepts header using Live Http Headers. You may need to do some explicit setup prior to the post.

---- wish I understood what you are trying to tell me here

My apologies. Not sure which part of the three above I should address, so here's all three.

1) Rails decides which respond_to block to use based on the request's Accept header. Here's a link that should help on that front.

2) Live HTTP is a plugin for Firefox that shows you the headers for each request-response cycle. I've pasted in the first frame you'll get visiting the link above below. It's got 2 sections. The first shows the headers sent on the request. The second shows the headers sent on the response. The Accept header content is on the 4th line of the request section. In this case, the client is telling the server that its first preference is for html and you can see from 2nd line in the response section that that is what the server sends back.

GET /blog/browser-rest-http-accept-headers HTTP/1.1

Host: www.gethifi.com

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.24) Gecko/20111107 Ubuntu/10.04 (lucid) Firefox/3.6.24

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 115

Connection: keep-alive

Referer: Redirect Notice

Cookie: __utma=1.1465277256.1325809449.1325809449.1325809449.1; __utmb=1.1.10.1325809449; __utmc=1; __utmz=1.1325809449.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); __lo__roomid=2489

Cache-Control: max-age=0

HTTP/1.1 200 OK

Content-Type: text/html

Expires: Thu, 05 Jan 12 19:20:20 -0500

Cache-Control: max-age=60

Vary: Accept-Encoding

Content-Encoding: gzip

Content-Length: 21416

Accept-Ranges: bytes

Connection: keep-alive

3) If what you see from looking at what's produced in Live HTTP by your post is that the request's Accept header is not requesting javascript (text/script iirc) then the problem is explained. The 'fix' is to set the request's Accept header. I did a quick google on 'jquery ajax set header' and got good results. This one looked like a good place to start. http://snipplr.com/view/9869/

This one might be a good look if the one above doesn't get you the results you need.

HTH, Bill

Then my best advice would be to double check the accepts header using Live Http Headers. You may need to do some explicit setup prior to the post.

---- wish I understood what you are trying to tell me here

My apologies. Not sure which part of the three above I should address, so here's all three.

1) Rails decides which respond_to block to use based on the request's Accept header. Here's a link that should help on that front. Understanding Browser HTTP Accept Headers: Firefox, Internet Explorer, Opera, and WebKit (Safari / Chrome)

2) Live HTTP is a plugin for Firefox that shows you the headers for each request-response cycle. I've pasted in the first frame you'll get visiting the link above below. It's got 2 sections. The first shows the headers sent on the request. The second shows the headers sent on the response. The Accept header content is on the 4th line of the request section. In this case, the client is telling the server that its first preference is for html and you can see from 2nd line in the response section that that is what the server sends back.

GET /blog/browser-rest-http-accept-headers HTTP/1.1

Host: www.gethifi.com

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.24) Gecko/20111107 Ubuntu/10.04 (lucid) Firefox/3.6.24

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 115

Connection: keep-alive

Referer: Redirect Notice

Cookie: __utma=1.1465277256.1325809449.1325809449.1325809449.1; __utmb=1.1.10.1325809449; __utmc=1; __utmz=1.1325809449.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); __lo__roomid=2489

Cache-Control: max-age=0

HTTP/1.1 200 OK

Content-Type: text/html

Expires: Thu, 05 Jan 12 19:20:20 -0500

Cache-Control: max-age=60

Vary: Accept-Encoding

Content-Encoding: gzip

Content-Length: 21416

Accept-Ranges: bytes

Date: Fri, 06 Jan 2012 00:25:13 GMT

Connection: keep-alive

3) If what you see from looking at what's produced in Live HTTP by your post is that the request's Accept header is not requesting javascript (text/script iirc) then the problem is explained. The 'fix' is to set the request's Accept header. I did a quick google on 'jquery ajax set header' and got good results. This one looked like a good place to start. http://snipplr.com/view/9869/

This one might be a good look if the one above doesn't get you the results you need. ajax - Cannot properly set the Accept HTTP header with jQuery - Stack Overflow

HTH