RFine wrote:

> 
> render :partial => 'comments/partial_name'
> 
> If I change it to :
> 
> render :partial => 'comments/partial_name.html.erb'
> 
> and it works. It appears as though the fact that the call is a JSON
> request from the client is causing the render engine not to search
> for .html and .html.erb in the path, thus they fail.

You got it. Why are you returning .html from a ajax/json request from 
the client, anyway?  Generally, ajax requests from the client get back 
javascript (or specifically json), not html!

Rails is trying to help you with this general case, because you can have 
the same action that will return partial.html.erb if it's an html 
request, or partial.js.erb if it's an AJAX request.  I forget exactly 
how Rails determines when the format is js, but I know if you're using 
any of the Rails helper methods for ajax callbacks, they definitely 
include a query param to tell Rails what's what.

So you can change the render call like you say. Or you COULD rename the 
partial in the old way partial_name.erb, so Rails will use it for any 
format request. But that's kind of weird (and now i'm not entirely sure 
it'll work).  Or you could reconsider why you want to return HTML 
(rather than js/json) to a js request in the first place. Or you could 
take a look at respond_to to see how you can return different views for 
different request types. 
http://api.rubyonrails.org/classes/ActionController/MimeResponds/InstanceMethods.html#M000368


-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to