Ruby on Rails: Sending javascript data to ruby controller

后端 未结 3 1572
野性不改
野性不改 2021-01-24 02:22

I would like to send a javascript array to be processed by a method in my controller. I think I am doing this way wrong. I am a total RoR, jquery, and ajax noobie. Here is what

相关标签:
3条回答
  • 2021-01-24 02:38

    Since you want it to respond in AJAX, you can tell Rails not to render anything by adding

    render :layout => false
    

    to the controller action

    0 讨论(0)
  • 2021-01-24 02:47

    You should either create a template in app/views/qtl_table/save.html.erb or render something in your controller. If nothing is rendered in the controller action, Rails tries to display default template, and you don't have one.

    0 讨论(0)
  • 2021-01-24 02:57

    Agreed with Riateche's answer. You'll need to add some logic to the controller to respond correctly.

    Looking at your console output, you can see the json data in the parameters hash. You can simply access the values in your controller as such:

    params["125,0,\"\",\"Ph upt 1-2\""]
    params["125,0,\"\",\"Ph upt 1-2\""][","]
    

    You can just map it your activerecord model and save it.

    0 讨论(0)
提交回复
热议问题