I'm having problems using the jsonifier plugin (I'm not using edge)
but I'm having trouble using :only, and :except.
If I do I get an ArgumentError wrong number of arguments (1 for 0).
Here is my code:
i don't know how jsoinifer plugin works,
but after installing this, if you are expecting it to override the
default to_json method(provided by rails),
then the code which you posted here is perfect, but if that plugin is
not overriding the to_json method of rails
then the code which you posted here is wrong, as you know
(default)to_json method won't accept any kind of argument.
this is what i know, sorry if it's not answering your question.
Cheers for that. The plugin works in some respects, removing the
'attributes' from every json object. So iI assume that means that
rails has found it and it is working but I still can't pass any
arguemtns??? One post here:
report that:
This gets me past the wrong number of arguments error:
format.json { render(:json => @customers.collect { |customer|
customer.to_json(:only => :name) } ) }
But I'm not exactly sure whats going on in that code.
This gives you the advantage of a layer of abstraction between your JS
code and Rails code, so if your column names change, you needn't
change your JavaScript.
Yes customising my JSON output is exactly what I want to do.
I only want to pass certain columns (I have a very simple example to
output category names) . I tried your suggestion by putting:
def to_json
{
:name => 'name'
}.to_json
end
Into my model and :
into my controller but I still get a "wrong number of arguments (1
for 0)".
Sorry if I am missing something quite fundamental but it looks like
rails still expects 0 arguments for the .to_json method??