Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Passing the format in the template name is deprecated. How? #6016

Closed
Sephi-Chan opened this Issue · 3 comments

2 participants

@Sephi-Chan

Hello,

I use JBuilder to populate JSON data into my views (for a Backbone app).
I was writing things like:

render("users/user.json", user: current_user)

But i receive a warning like:

DEPRECATION WARNING: Passing the format in the template name is deprecated. Please pass render with :formats => [:json] instead.

But now I don't know what to write to get it working. I unsuccessfully tried some combination but it always leads to a:

Missing partial users/user with {:locale=>[:fr], :formats=>[:html], :handlers=>[:erb, :builder, :jbuilder, :coffee, :haml]}.

Both the guides and the API seems outdated. :s
What should I do?

Thanks a lot!

@carlosantoniodasilva

@Sephi-Chan Try like this:

render("users/user", formats: :json, user: current_user)

And please feel free to contribute to the guides / api if they feel outdated about it :). Thanks.

@Sephi-Chan

@carlosantoniodasilva It still raises:

Missing partial users/user with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :jbuilder, :coffee, :haml]}.

I got it working with the following code:

- json = render(partial: 'users/user', formats: [:json], locals: { user: @user })

I would be glad to contribute to the API but I'm unexperienced so please tell me: Is it okay to just complete the documentation of ActionView::Helpers::RenderingHelper#render to indicate the existence of these options?

@carlosantoniodasilva

Ops yeah, it's required to use render :partial in this case, forgot that, sorry. If you need to use any available option, such as :format or :layout, you always need to use render :partial.

Doc contributions are always welcome, of course :). Feel free to expand the api or the guides with more info, you can do that directly in lifo/docrails, it's a branch of rails only for doc contributions, and you can push freely. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.