understanding the to_json method

Hello,

I am using the to_json method to encode models to json. Standard stuff. I am using the :include option so that a relation model gets added to the encoded json. Again this is fine however the related model is a user model that has things like md5 password strings. Whats the best way of excluding these fields form the encoding. Here is the current line of code that calls the to_json method

format.js { render :json => @shifts.to_json(:include => [ :users ]) }

Stewart wrote in post #989366:

Hello,

I am using the to_json method to encode models to json. Standard stuff. I am using the :include option so that a relation model gets added to the encoded json. Again this is fine however the related model is a user model that has things like md5 password strings. Whats the best way of excluding these fields form the encoding. Here is the current line of code that calls the to_json method

format.js { render :json => @shifts.to_json(:include => [ :users ]) }

I believe you want:

@shifts.to_json(:include => { :users => { :except =>[ 'password'] }})