nico_lrx
nico_lrx

Reputation: 290

Rails 7 missing partial

I am upgrading to Rails 7.1 and get a weird error in a view using a JS partial:

Missing partial account/_stripe.js.erb, application/_stripe.js.erb with {:locale=>[:fr], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}.

Here is my code to render the partial (it works well with Rails 6):

<%= render "stripe.js.erb" %>

The partial is located in the same folder as the view and is named "_stripe.js.erb".

I tried to replace the name of the partial, as suggested, by account/stripe, account/stripe.js, account/stripe.js.erb, stripe, stripe.js, none works.

Any idea how to solve this with Rails 7? Thanks.

Upvotes: 16

Views: 4625

Answers (2)

Paul Cantrell
Paul Cantrell

Reputation: 9324

Encountering a similar error, in my case the problem was code like this (yes, predating modern Ruby’s symbol key syntax!):

:formats => ['html']

The string value for formats worked up through Rails 6, but fails with the error above in Rails 7. Changing it to a symbol fixed the problem for me:

:formats => [:html]

(Note that the equivalent formats: [:html] and formats: :html also work.)

Upvotes: 0

AbM
AbM

Reputation: 7779

Having an extension in the partial name was deprecated in Rails 6.1 and removed in Rails 7. You should use the following syntax:

<%= render partial: 'stripe', formats: :js %>

Upvotes: 29

Related Questions