Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow templates with alternate mime types #120

Closed
wants to merge 1 commit into from
Closed

Conversation

paul
Copy link

@paul paul commented Apr 1, 2013

Trying to use jbuilder with an alternative mime type (eg, application/hal+json) does not work for partial templates because jbuilder forcibly sets the format to :json in the #partial! method. This is the error I get:

Started GET "/accounts" for 127.0.0.1 at 2013-04-01 16:41:59 -0600
Processing by AccountsController#index as HAL
  Account Load (0.2ms)  SELECT "accounts".* FROM "accounts"
  Credentials Load (0.2ms)  SELECT "credentials".* FROM "credentials" WHERE "credentials"."account_id" IN (1)
  Rendered accounts/index.hal.jbuilder (30.7ms)
Completed 500 Internal Server Error in 32ms

ActionView::Template::Error (Missing partial accounts/account with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}. Searched in:
  * "/Users/rando/Code/librato/cloudsnarf/app/views"
):
     8:   json.self link(accounts_url)
     9: end
    10: json._embedded do
    11:   json.accounts(@accounts) { |account| json.partial! account }
    12: end
  app/views/accounts/index.hal.jbuilder:11:in `block (2 levels) in _app_views_accounts_index_hal_jbuilder___3338183405941646797_70245895658780'
  app/views/accounts/index.hal.jbuilder:11:in `block in _app_views_accounts_index_hal_jbuilder___3338183405941646797_70245895658780'
  app/views/accounts/index.hal.jbuilder:10:in `_app_views_accounts_index_hal_jbuilder___3338183405941646797_70245895658780'


  Rendered /Users/rando/.rvm/gems/ruby-2.0.0-p0@cloudsnarf/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
  Rendered /Users/rando/.rvm/gems/ruby-2.0.0-p0@cloudsnarf/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
  Rendered /Users/rando/.rvm/gems/ruby-2.0.0-p0@cloudsnarf/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (8.4ms)

I make a request with Accept: application/hal+json, Rails finds the accounts/index.hal.jbuilder template, and loads it correctly. That template uses the "account" partial, but because the #partial! method sets the format to :json, Rails tries to find a accounts/_account.json.jbuilder template, while I have it named accounts/_account.hal.jbuilder.

This change just removes setting the format. I'm not sure the original purpose of it, and all the tests pass without it.

@rwz
Copy link
Collaborator

rwz commented Apr 2, 2013

Could you please try this branch and report if it solves your problem?

@paul
Copy link
Author

paul commented Apr 2, 2013

@rwz From my quick test, that also seems to solve the issue.

@rwz
Copy link
Collaborator

rwz commented Apr 11, 2013

It actually broke some working code in my app. I'm not sure why yet, but seems related to that bug. Will investigate more.

@tal
Copy link

tal commented Apr 30, 2013

Would rather see the default formats configurable then just removing the designation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants