Outputting jSON in a rails app

前端 未结 3 1606
我寻月下人不归
我寻月下人不归 2021-02-04 12:34

ok, rails 3 new developer here.

I want my jquery to be able to get a json object from the rails 3 application for projects. Here is my controller.

def yo         


        
3条回答
  •  没有蜡笔的小新
    2021-02-04 13:19

    :formats=>[:html]
    

    That says the server is thinking that html is being requested. Try adding a .json to your path (and possible route) and that will force the format. TO make that would would need a route something like this:

    map.your_projects '/projects/yourprojects.:format',
      :controller => 'projects',
      :action => 'yourprojects'
    

    Somehow, someway, the params[:format] should be "json" for this request so the format handlers can do the right thing.

提交回复
热议问题