I am trying to use jbuilder to create a json file from an event list. It must be in a specific format. Currently, no matter what I put in the jbuilder file, when you go to /1/events.json users, the file is empty (just {}).
I tried to put the response to the block in the controller, but then it just returns the list of events in the wrong format.
I think the routes were executed correctly because the log file says that the file myevents.json.jbuilder was successfully displayed when url / users / 1 / myevents.json was requested. Also, when .html is requested, the myevents.html file displays well, with all the information in it.
I am really a dead end in this, any help would be greatly appreciated!
I have listed all the relevant code if anyone can pick something up:
event controller:
def myevents @events = current_user.events end
myevents.json.jbuilder:
Jbuilder.encode do |json| json.timeline do json.headline current_user.first_name json.type "default" json.text "A Timeline" json.start_date json.array!(@events) do |event| json.start_date event.start_date json.end_date event.end_date json.headline event.headline json.text event.text json.asset do json.media event.media json.credit event.credit json.caption event.caption end end end end
environment.rb:
Jbuilder.key_format :camelize => :lower
routes.rb:
match 'users/:id/events' => 'events#myevents'
source share