Missing template after link_to_remote

1.6k views Asked by At

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!

2

There are 2 answers

2
EmFi On

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'
2
Tilendor On

Try removing the / in front of shared.

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