Missing template after link_to_remote

I am using link_to_remote to update a partial part on my page. The problem is that Rails doesn't find my partial.

I am specifying the full path to my partial (html.erb file) in a 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 as "something" is being created. I am getting error "Template missing [:controller_name]/[:method_name].js.erb not found"

.

Can anyone explain why Rails seems to use the default path to js.erb?

Thanks in advance!

+2


source to share


2 answers


Rails responds to the JS format. render: partial does not count as action 1 render / redirect call for every action. Without a proper render call or redirect, Rails will call the render with default arguments based on format, controller, and action.

Render: partial just returns the text to the caller, it doesn't create a response. In this case, the partial part is rendered in HTML, but nothing is done about it. Postscript: layout => false option is superfluous when rendering partial.

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

Assuming you want to replace the entire webpage, the short version does something like this:



def my_method create something

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

      

On the RJS path, you can create a file app / views / resource / my_method.rjs and populate it

page.replace_html :body, :partial => '/shared/partials/my_partial_form'

      

+2


source


Try to remove / before general.



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

      

0


source







All Articles