Mohamed El Mahallawy
Mohamed El Mahallawy

Reputation: 13862

Jbuilder without the .json extension

Doing http://localhost:3000/options/audio

And I get error:

Missing template options/audio, application/audio with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/Users/mmahalwy/Desktop/Code/quran.com/QuranAPI/app/views"

When I do http://localhost:3000/options/audio.json

That renders my Jbuilder file and the desired json. How can I render my jbuilder template with the .json extension?

Upvotes: 3

Views: 1508

Answers (2)

watzon
watzon

Reputation: 2549

The jbuilder documentation tells you to create your jbuilder template as a *.json.jbuilder file. This makes the route look for the .json extension. If you remove the .json part and make your file *.jbuilder you will be able to go to the route without the .json extension.

Example:

Filename: index.jbuilder route: get 'ticket', to: 'tickets#index'

Upvotes: 3

Ruby Racer
Ruby Racer

Reputation: 5740

jbuilder is a gem, a tool.... I haven't tried it but if you want default functionality (html) with json and jbuilder, then:

http://localhost:3000/options/audio

will look for

/Users/mmahalwy/Desktop/Code/quran.com/QuranAPI/app/views/.../audio.html.jbuilder

So, you can put your code in there... But it can only be jbuilder code... Otherwise, you can use a plain html.erb or other file with embedded ruby and you will specify jbuilder json creation in it:

Jbuilder.encode do |json| # this is implied in .jbuilder files but can be used in any other ruby file
     json.xxx @yyy.xxx
     #....
end

Upvotes: 0

Related Questions