nesquena/rabl — Issue #176: 'render' method in rails does not work
Author: andreareginato
Created: 2012-02-28 13:57:44+00:00
State: open

Hi, I'm using rabl to build my APIs and all works fine when defining 'index' and 'show' action.
The problem comes up when defining the 'create' action, where the object @device result
always nil. I've searched on issue list and around the web, but I didn't found a solution.

# devices_controller.rb
def create
@device = ...
if @device.save
render 'show', status: 201, location: @device.uri
else
render_422 "notifications.resource.not_valid", @device.errors
end
end

# show.json.rabl

object @device

node(:uri) { |device| device.uri }
node(:id) { |device| device.id }
node(:name) { |device| device.name }
node(:type) { |device| { uri: device.type_uri } }

node(:properties) do |device|
device.device_properties.map do |property|
{ uri: property.uri, value: property.value }
end
end

node(:physical) do |device|
{ uri: device.device_physicals.first.uri }
end

node(:created_at) { |device| device.created_at }
node(:updated_at) { |device| device.updated_at }