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)

<%= flash[:messages1].html_safe %>
    <% for u in @users -%>
  • <%= u.uid %>
  • <% end -%>

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

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

Showing
/home/users/cwhite/tti_framework/app/views/permissions/add_member.erb
where line #1 raised:

Missing partial permissions/permission with 
{:locale=>[:en, :en], :handlers=>[:coffee, :builder, :erb], 
:formats=>[:html]}. Searched in:
  * "/home/users/cwhite/tti_framework/app/views"

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


Craig W. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[email protected]
1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Need help communicating between generations at work to achieve your
desired success? Let us help!

Hi Craig,

On Thu, Jan 5, 2012 at 4:18 PM, Craig W. [email protected]
wrote:

Missing template ... :formats=>[:html]}.

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

HTH,
Bill

On Jan 5, 2012, at 3:37 PM, Bill W. wrote:

Hi Craig,

On Thu, Jan 5, 2012 at 4:18 PM, Craig W. [email protected] wrote:

Missing template ... :formats=>[: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.

my js is a bit involved…

$(function() {
$("#priv_users").on(“mouseenter”, function() {
!$(“li:first”, this).hasClass(“ui-draggable”) && $(“li”,
this).draggable();
});
$("[id^=privileges-]").droppable({
drop: function(event, ui) {
$(this).addClass(“ui-state-highlight”);
$.post("/permissions/add_member/", {
“uid”: ui.draggable.attr(“data-add”),
“id”: $(this).attr(“id”)
}, function(data) {
var html = $(data);
$("#messages1").replaceWith(html.closest("#messages1"));
});
}
});
})

Craig

On Thu, Jan 5, 2012 at 4:44 PM, Craig W. [email protected]
wrote:


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

On Jan 5, 2012, at 3:57 PM, Bill W. wrote:

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.


wish I understood what you are trying to tell me here

Craig

On Thu, Jan 5, 2012 at 5:18 PM, Craig W. [email protected]
wrote:

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

Javier

On Jan 5, 2012, at 4:41 PM, Javier Q. wrote:

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

Thanks in advance


actually I am using replaceWith in some places in my js code itself but
the code in add_member.js.erb isn’t getting executed at all and it’s
responding to html instead.

Craig

On Thu, Jan 5, 2012 at 5:26 PM, Craig W. [email protected]
wrote:

On Jan 5, 2012, at 3:57 PM, Bill W. wrote:

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.
    http://www.gethifi.com/blog/browser-rest-http-accept-headers

  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:
http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CDwQFjAC&url=http%3A%2F%2Fwww.gethifi.com%2Fblog%2Fbrowser-rest-http-accept-headers&ei=9z4GT6y7K4X-sQKd25SRCg&usg=AFQjCNFXKdbpcUNstr0O0jkYtWvhb4EjYQ&sig2=Ycrt2dIClGHE4IldZUeJzw

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

  1. 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.
http://stackoverflow.com/questions/1145588/cannot-properly-set-the-accept-http-header-with-jquery

HTH,
Bill

On Jan 5, 2012, at 5:52 PM, Bill W. wrote:

My apologies. Not sure which part of the three above I should
sent on the response. The Accept header content is on the 4th line of
Gecko/20111107 Ubuntu/10.04 (lucid) Firefox/3.6.24

Vary: Accept-Encoding

results you need.

http://stackoverflow.com/questions/1145588/cannot-properly-set-the-accept-http-header-with-jquery

HTH


Probably does help but this is my ‘side’ project at work - done on my
slack time and I have had my hands full so I didn’t get any time to do
much with it but I wanted to acknowledge your e-mail, say thanks but it
may be a few more days before I get the time to go through it all.

Craig

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs