xamenrax
xamenrax

Reputation: 1744

Ruby on Rails fail when refresh page with ajax

Cheers! I have remote action in my rails project, smth like:

def foo
  respond_to do |format|
    format.js {}
  end
end

Somewhere in view:

= link_to "foo", foo_path, remote: true

In my foo.js.erb file:

$('#bar').html("<%= j render(partial: 'bar') %>");

In my _bar.html.haml partial:

hello, i am bar

It's all okay and well-working, but it returns me Missing template error when I refreshing page on this route. What's the problem?

Upvotes: 1

Views: 124

Answers (1)

Jon Cairns
Jon Cairns

Reputation: 11951

If you're mixing different formats (in this case, erb and haml), you'll need to specify the format of the partial.

This question provides the answer. Instead of render(partial: 'bar'), use:

$('#bar').html("<%= j render(partial: '/path/bar.html.haml') %>");

Upvotes: 1

Related Questions