-
Notifications
You must be signed in to change notification settings - Fork 54
How do I do ... with Webmachine?
kgish edited this page Jan 2, 2015
·
5 revisions
def finish_request
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Content-Type, ...'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE'
end
end
def allowed_methods
["PUT"]
end
def content_types_accepted
[["application/json", :from_json]]
end
def resource_exists?
widget
end
def from_json
response_code = widget ? 200 : 201
# create or update widget...
response_code
end
private
def widget
@widget ||= Widget.find(request.path_info[:id])
end
def is_authorized?
# Implement any logic you like here, return truthy or falsey
end