In my controller I have:
@pakkes = Pakke.where("navn like ?", "%#{params[:q]}%")
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @pakkes }
format.json { render :json => @pakkes.map(&:attributes) }
end
How do I change the attribute navn to name when rendering JSON?
You can do this with a one-line method in
Pakke:Calling
superwill generate json hash as usual, then before it’s returned you’ll swoop in and change the key of the “navn” entry.