rails 2.3.5 action renders json to accounts/images instead of accounts/images.json
I am fairly new to rails and i am having trouble with rendering json files. I have this action in my accounts controller:
def images
user = current_user #|| current_fb_user
img_urls = []
user.images.each do |img|
unless img.deleted_at || !img.verified_to_s3
img_urls << img.url
end
end
render :开发者_开发知识库json => img_urls
end
this renders a json, but it renders it at "/accounts/images" instead of "/accounts/images.json" (i get a template missing when i try images.json) as an actual .json file. How do i write the code so i can get a .json file?
Thanks
Try putting:
respond_to :json
at the top of your controller and:
respond_with img_urls
instead of render :json => img_urls
精彩评论