views:

642

answers:

2

I'm using link_to_remote to update a partial on my page. The problem is that Rails isn't finding my partial.

I am specifying the full path to my partial(an html.erb file) in the controller method:

def my_method
 create something

 render :partial => '/shared/partials/my_partial_form', :layout => 'false'
end

I know the controller method is getting hit, since "something" gets created. I get the error "Template missing [:controller_name]/[:method_name].js.erb not found".

Can anyone explain why Rails appears to be using a default path to a js.erb?

Thanks in advance!

A: 

Rails is responding to the JS format. render :partial doesn't count as the action's 1 render/redirect call per action. Without a proper render or redirect call, Rails will call render with default arguments based on the format, controller and action.

Render :partial just returns text to the caller, it does not build a response. In this case the partial is rendered into HTML, but then nothing is done with it. P.S. :layout => false option is superfluous when rendering a partial.

You want to use render :update or RJS files to do the same through a template.

Assuming you want to replace the entire web page, the short version is do something like this:

def my_method create something

  render :update do |page|
    page.replace_html :body, :partial => '/shared/partials/my_partial_form'    
  end
end

Going the RJS route you could create the app/views/resource/my_method.rjs file and fill it with

page.replace_html :body, :partial => '/shared/partials/my_partial_form'
EmFi
Thank you for the response. I have used link_to_remote to update a div elsewhere in this same codebase. In those cases, as long as the last line in the method was render :partial everything was fine. I'm eager to understand what makes this different. Possible culprits:controller inheritanceplugin on the pageI tried your first suggestion and it returns the same error. In fact, everything I've tried leaves me in the same place. Replacing the :partial with redirect_to root_url also yields no different results. I see that this is because rails doesn't acknowledge the directive as valid.
logia
When Rails responds to a JS request it sends javascript to be run in the browser. All ruby methods return the result of the last statement. redirect_root_url doesn't change the format of the request, so again, if you're not explicitly stating the template to generate the Javascript, Rails will render the default. Which explains why your error doesn't change with redirect_root_url
EmFi
This isn't working for me. Did it work for you logia?
GreenRails
A: 

Try removing the / in front of shared.

render :partial => 'shared/partials/my_partial_form', :layout => 'false'
Tilendor
thanks. tried that. at this point i would love to have it tell me another error-- any other. possible sources of difference:controller inheritance-i've tried putting the method in the parent controller and in the child controller. same error- there is a plugin on the page to handle multiple forms on a single page.
logia
and my_partial_form is named _my_partial_form.html.erb?
Tilendor