Json views

Hi *, I’m writing an API for my application, but I can’t figure out
how to behave with the json frontend, where I need to do something
like @object.image.url.
Should I write a .json view or there’s some special method for this
kind of problems ? I see to_json has a handy methods option that
should call the method and put it in the output, but the problem here
is that image is a Paperclip object (that contains also my S3 keys, so
it’s really not the case :p) and I need to call the url method.
Suggestions ?

ngw

On Monday 03 August 2009, Nicholas W. wrote:

Hi *, I’m writing an API for my application, but I can’t figure out
how to behave with the json frontend, where I need to do something
like @object.image.url.
Should I write a .json view or there’s some special method for this
kind of problems ?

In case you decide that JSON views are what you want, have a look at a
(trivial) template handler I wrote to help with just that

http://github.com/mschuerig/ruby_template_handler

Michael


Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/

Il giorno 03/ago/09, alle ore 20:10, Michael S. ha scritto:

http://github.com/mschuerig/ruby_template_handler

Nice, thanks a lot.
What do I have to include to use it ? Right now by following the
example my only result is to have a string in return.

ngw

On Tuesday 04 August 2009, Nicholas W. wrote:

http://github.com/mschuerig/ruby_template_handler

Nice, thanks a lot.
What do I have to include to use it ?

You can install the handler either as a plugin using script/plugin or as
a gem. In the latter case you have to add

config.gem “mschuerig-ruby_template_handler”,
:lib => ‘ruby_template_handler’

to config/environment.rb.

Right now by following the
example my only result is to have a string in return.

Well, what else do you want to return? The body of your response is
always going to be a string, in this case a string in JSON format.

Michael


Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs